Skip to content

Commit

Permalink
refactor: geometry encoder and decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
HideBa committed Jan 13, 2025
1 parent e5c14a9 commit 778a7a7
Show file tree
Hide file tree
Showing 5 changed files with 935 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/fbs/header.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum ColumnType: ubyte {
}

table Column {
index: ushort; // Column index (0 = first column)
index: ushort; // Column index (0 = first column) This index is used to identify the column in the FlatBuffer. The reason why index is used instead of column name is to save more space on attribute field.
name: string (required); // Column name
type: ColumnType; // Column type
title: string; // Column title
Expand Down
42 changes: 30 additions & 12 deletions src/rust/src/reader/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use crate::{
feature_generated::{CityFeature, CityObjectType, Geometry, Vertex},
geometry_encoderdecoder::FcbGeometryEncoderDecoder,
geom_decoder::{decode, decode_semantics},
header_generated::*,
};
use anyhow::{Context, Result};
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn to_cj_feature(
.iter()
.map(|co| {
let geographical_extent = co.geographical_extent().map(|extent| {
vec![
[
extent.min().x(),
extent.min().y(),
extent.min().z(),
Expand Down Expand Up @@ -330,21 +330,39 @@ pub fn to_cj_feature(
}

pub(crate) fn decode_geometry(g: Geometry) -> Result<CjGeometry> {
let decoder = FcbGeometryEncoderDecoder::new_as_decoder(
g.solids().map(|v| v.iter().collect()),
g.shells().map(|v| v.iter().collect()),
g.surfaces().map(|v| v.iter().collect()),
g.strings().map(|v| v.iter().collect()),
g.boundaries().map(|v| v.iter().collect()),
);

let boundaries = decoder.decode();
let solids = g
.solids()
.map(|v| v.iter().collect::<Vec<_>>())
.unwrap_or_default();
let shells = g
.shells()
.map(|v| v.iter().collect::<Vec<_>>())
.unwrap_or_default();
let surfaces = g
.surfaces()
.map(|v| v.iter().collect::<Vec<_>>())
.unwrap_or_default();
let strings = g
.strings()
.map(|v| v.iter().collect::<Vec<_>>())
.unwrap_or_default();
let indices = g
.boundaries()
.map(|v| v.iter().collect::<Vec<_>>())
.unwrap_or_default();
let boundaries = decode(&solids, &shells, &surfaces, &strings, &indices);
let semantics: Option<CjSemantics> = if let (Some(semantics_objects), Some(semantics)) =
(g.semantics_objects(), g.semantics())
{
let semantics_objects = semantics_objects.iter().collect::<Vec<_>>();
let semantics = semantics.iter().collect::<Vec<_>>();
Some(decoder.decode_semantics(g.type_(), semantics_objects, semantics))
Some(decode_semantics(
&solids,
&shells,
g.type_(),
semantics_objects,
semantics,
))
} else {
None
};
Expand Down
Loading

0 comments on commit 778a7a7

Please sign in to comment.