From a3382b737b28fddc2f504d73ef7f4b53cf59d728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B6ber?= Date: Fri, 20 Apr 2018 10:47:08 +0200 Subject: [PATCH 1/6] Fix conversion of transparency Also changed the code to use more automatic type deduction. Transparency was wrongly taken from SufaceStyleRendering, although it is already available in SurfaceStyleShading. --- .../src/ifcpp/geometry/StylesConverter.h | 102 +++++++++--------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h index 255822188..eb2709dd8 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h @@ -168,28 +168,27 @@ class StylesConverter : public StatusCallback } - void convertIfcSurfaceStyle( shared_ptr surface_style, shared_ptr& appearance_data ) + void convertIfcSurfaceStyle( + shared_ptr const& surface_style, + shared_ptr& appearance_data ) { if( !surface_style ) - { return; - } - const int style_id = surface_style->m_entity_id; + + auto const style_id = surface_style->m_entity_id; auto it_find_existing_style = m_map_ifc_styles.find( style_id ); if( it_find_existing_style != m_map_ifc_styles.end() ) { // todo: check if appearance compare is faster here appearance_data = it_find_existing_style->second; if( appearance_data->m_complete ) - { return; - } } else { if( !appearance_data ) { - appearance_data = shared_ptr( new AppearanceData( style_id ) ); + appearance_data = std::make_shared(style_id); } #ifdef ENABLE_OPENMP @@ -199,27 +198,23 @@ class StylesConverter : public StatusCallback } appearance_data->m_apply_to_geometry_type = AppearanceData::GEOM_TYPE_SURFACE; - std::vector >& vec_styles = surface_style->m_Styles; + auto const& vec_styles = surface_style->m_Styles; if( vec_styles.size() == 0 ) - { return; - } - for( size_t ii_styles = 0; ii_styles < vec_styles.size(); ++ii_styles ) + for( auto const& surf_style_element_select : vec_styles ) { - shared_ptr surf_style_element_select = vec_styles[ii_styles]; if( !surf_style_element_select ) - { continue; - } + // TYPE IfcSurfaceStyleElementSelect = SELECT (IfcExternallyDefinedSurfaceStyle ,IfcSurfaceStyleLighting ,IfcSurfaceStyleRefraction ,IfcSurfaceStyleShading ,IfcSurfaceStyleWithTextures); - shared_ptr surface_style_shading = dynamic_pointer_cast( surf_style_element_select ); + auto const surface_style_shading = dynamic_pointer_cast( surf_style_element_select ); if( surface_style_shading ) { vec4 surface_color( 0.8, 0.82, 0.84, 1.0 ); if( surface_style_shading->m_SurfaceColour ) { - shared_ptr surf_color = surface_style_shading->m_SurfaceColour; + auto const& surf_color = surface_style_shading->m_SurfaceColour; convertIfcColourRgb( surf_color, surface_color ); } @@ -231,49 +226,44 @@ class StylesConverter : public StatusCallback vec4 ambient_color( surface_color ); vec4 diffuse_color( surface_color ); vec4 specular_color( surface_color ); - double shininess = 35.f; - double transparency = surface_color.a(); - bool set_transparent = false; + auto shininess = 35.; + auto transparency = surface_color.a(); + auto set_transparent = false; + + if (surface_style_shading->m_Transparency) + { + // in IFC 1 is transparent, 0 is opaque. if not given, the value 0 (opaque) is assumed + // in osg, 1 is opaque, 0 is transparent + transparency = 1. - surface_style_shading->m_Transparency->m_value; + if (transparency < 0.1) + transparency = 0.1; - shared_ptr surf_style_rendering = dynamic_pointer_cast( surf_style_element_select ); + if (transparency > 1.) + transparency = 1.; + + if (transparency < 0.99) + set_transparent = true; + } + + auto const surf_style_rendering = dynamic_pointer_cast( surf_style_element_select ); if( surf_style_rendering ) { if( surf_style_rendering->m_DiffuseColour ) { - shared_ptr color_or_factor = surf_style_rendering->m_DiffuseColour; + auto const& color_or_factor = surf_style_rendering->m_DiffuseColour; convertIfcColourOrFactor( color_or_factor, surface_color, diffuse_color ); } if( surf_style_rendering->m_SpecularColour ) { - shared_ptr ifc_specular_color = surf_style_rendering->m_SpecularColour; + auto const& ifc_specular_color = surf_style_rendering->m_SpecularColour; convertIfcColourOrFactor( ifc_specular_color, surface_color, specular_color ); } - if( surf_style_rendering->m_Transparency ) - { - // in IFC 1 is transparent, 0 is opaque. if not given, the value 0 (opaque) is assumed - // in osg, 1 is opaque, 0 is transparent - transparency = 1.f - (float)surf_style_rendering->m_Transparency->m_value; - if( transparency < 0.1f ) - { - transparency = 0.1f; - } - - if( transparency > 1.f ) - { - transparency = 1.f; - } - - if( transparency < 0.99f ) - { - set_transparent = true; - } - } if( surf_style_rendering->m_SpecularHighlight ) { - shared_ptr spec_highlight = surf_style_rendering->m_SpecularHighlight; + auto const& spec_highlight = surf_style_rendering->m_SpecularHighlight; convertIfcSpecularHighlightSelect( spec_highlight, appearance_data ); shininess = appearance_data->m_specular_roughness * 128; if( shininess <= 1.0 ) @@ -283,9 +273,21 @@ class StylesConverter : public StatusCallback } } - appearance_data->m_color_ambient.setColor( ambient_color.r()*0.8, ambient_color.g()*0.8, ambient_color.b()*0.8, transparency ); - appearance_data->m_color_diffuse.setColor( diffuse_color.r(), diffuse_color.g(), diffuse_color.b(), transparency ); - appearance_data->m_color_specular.setColor( specular_color.r()*0.1, specular_color.g()*0.1, specular_color.b()*0.1, transparency ); + appearance_data->m_color_ambient.setColor( + ambient_color.r()*0.8, + ambient_color.g()*0.8, + ambient_color.b()*0.8, + transparency ); + appearance_data->m_color_diffuse.setColor( + diffuse_color.r(), + diffuse_color.g(), + diffuse_color.b(), + transparency ); + appearance_data->m_color_specular.setColor( + specular_color.r()*0.1, + specular_color.g()*0.1, + specular_color.b()*0.1, + transparency ); appearance_data->m_shininess = shininess; appearance_data->m_set_transparent = set_transparent; @@ -294,7 +296,7 @@ class StylesConverter : public StatusCallback continue; } - shared_ptr ext_surf_style = dynamic_pointer_cast( surf_style_element_select ); + auto const ext_surf_style = dynamic_pointer_cast( surf_style_element_select ); if( ext_surf_style ) { #ifdef _DEBUG @@ -303,7 +305,7 @@ class StylesConverter : public StatusCallback continue; } - shared_ptr style_lighting = dynamic_pointer_cast( surf_style_element_select ); + auto const style_lighting = dynamic_pointer_cast( surf_style_element_select ); if( style_lighting ) { #ifdef _DEBUG @@ -312,7 +314,7 @@ class StylesConverter : public StatusCallback continue; } - shared_ptr style_refraction = dynamic_pointer_cast( surf_style_element_select ); + auto const style_refraction = dynamic_pointer_cast( surf_style_element_select ); if( style_refraction ) { #ifdef _DEBUG @@ -321,7 +323,7 @@ class StylesConverter : public StatusCallback continue; } - shared_ptr style_texture = dynamic_pointer_cast( surf_style_element_select ); + auto const style_texture = dynamic_pointer_cast( surf_style_element_select ); if( style_texture ) { #ifdef _DEBUG From ca51f818952c2e47d80e15a00f2785b1a849de18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B6ber?= Date: Fri, 20 Apr 2018 13:42:12 +0200 Subject: [PATCH 2/6] Add private function section --- .../src/ifcpp/geometry/StylesConverter.h | 179 +++++++++--------- 1 file changed, 89 insertions(+), 90 deletions(-) diff --git a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h index eb2709dd8..9e4109f39 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h @@ -78,96 +78,6 @@ class StylesConverter : public StatusCallback { m_map_ifc_styles.clear(); } - - void convertIfcSpecularHighlightSelect( shared_ptr highlight_select, shared_ptr& appearance_data ) - { - if( dynamic_pointer_cast( highlight_select ) ) - { - shared_ptr spec = dynamic_pointer_cast( highlight_select ); - appearance_data->m_specular_exponent = spec->m_value; - } - else if( dynamic_pointer_cast( highlight_select ) ) - { - shared_ptr specular_roughness = dynamic_pointer_cast( highlight_select ); - appearance_data->m_specular_roughness = specular_roughness->m_value; - } - } - - void convertIfcColourRgb( shared_ptr color_rgb, vec4& color ) - { - if( color_rgb->m_Red ) - { - color.m_r = (float)color_rgb->m_Red->m_value; - } - if( color_rgb->m_Green ) - { - color.m_g = (float)color_rgb->m_Green->m_value; - } - if( color_rgb->m_Blue ) - { - color.m_b = (float)color_rgb->m_Blue->m_value; - } - } - - void convertIfcColourOrFactor( shared_ptr color_or_factor, vec4& src_color, vec4& target_color ) - { - // TYPE IfcColourOrFactor = SELECT ( IfcNormalisedRatioMeasure, IfcColourRgb); - shared_ptr color_rgb = dynamic_pointer_cast( color_or_factor ); - if( color_rgb ) - { - convertIfcColourRgb( color_rgb, target_color ); - return; - } - - shared_ptr ratio_measure = dynamic_pointer_cast( color_or_factor ); - if( ratio_measure ) - { - float factor = ratio_measure->m_value; - target_color.setColor( src_color.r()*factor, src_color.g()*factor, src_color.b()*factor, src_color.a() ); - return; - } - } - - void convertIfcColour( shared_ptr ifc_color_select, vec4& color ) - { - // IfcColour = SELECT ( IfcColourSpecification, IfcPreDefinedColour ); - shared_ptr color_spec = dynamic_pointer_cast( ifc_color_select ); - if( color_spec ) - { - // ENTITY IfcColourSpecification ABSTRACT SUPERTYPE OF(IfcColourRgb); - shared_ptr color_rgb = dynamic_pointer_cast( color_spec ); - if( color_rgb ) - { - convertIfcColourRgb( color_rgb, color ); - } - return; - } - - shared_ptr predefined_color = dynamic_pointer_cast( ifc_color_select ); - if( predefined_color ) - { - // ENTITY IfcPreDefinedColour ABSTRACT SUPERTYPE OF(IfcDraughtingPreDefinedColour) - shared_ptr draughting_predefined_color = dynamic_pointer_cast( predefined_color ); - if( draughting_predefined_color ) - { - if( draughting_predefined_color->m_Name ) - { - std::wstring predefined_name = draughting_predefined_color->m_Name->m_value; - if( boost::iequals( predefined_name, L"black" ) ) color.setColor( 0.0, 0.0, 0.0, 1.0 ); - else if( boost::iequals( predefined_name, L"red" ) ) color.setColor( 1.0, 0.0, 0.0, 1.0 ); - else if( boost::iequals( predefined_name, L"green" ) ) color.setColor( 0.0, 1.0, 0.0, 1.0 ); - else if( boost::iequals( predefined_name, L"blue" ) ) color.setColor( 0.0, 0.0, 1.0, 1.0 ); - else if( boost::iequals( predefined_name, L"yellow" ) ) color.setColor( 1.0, 1.0, 0.0, 1.0 ); - else if( boost::iequals( predefined_name, L"magenta" ) ) color.setColor( 1.0, 0.0, 1.0, 1.0 ); - else if( boost::iequals( predefined_name, L"cyan" ) ) color.setColor( 0.0, 1.0, 1.0, 1.0 ); - else if( boost::iequals( predefined_name, L"white" ) ) color.setColor( 1.0, 1.0, 1.0, 1.0 ); - } - } - return; - } - } - - void convertIfcSurfaceStyle( shared_ptr const& surface_style, shared_ptr& appearance_data ) @@ -563,6 +473,95 @@ class StylesConverter : public StatusCallback return; } +private: + void convertIfcSpecularHighlightSelect( shared_ptr highlight_select, shared_ptr& appearance_data ) + { + if( dynamic_pointer_cast( highlight_select ) ) + { + shared_ptr spec = dynamic_pointer_cast( highlight_select ); + appearance_data->m_specular_exponent = spec->m_value; + } + else if( dynamic_pointer_cast( highlight_select ) ) + { + shared_ptr specular_roughness = dynamic_pointer_cast( highlight_select ); + appearance_data->m_specular_roughness = specular_roughness->m_value; + } + } + + void convertIfcColourRgb( shared_ptr color_rgb, vec4& color ) + { + if( color_rgb->m_Red ) + { + color.m_r = (float)color_rgb->m_Red->m_value; + } + if( color_rgb->m_Green ) + { + color.m_g = (float)color_rgb->m_Green->m_value; + } + if( color_rgb->m_Blue ) + { + color.m_b = (float)color_rgb->m_Blue->m_value; + } + } + + void convertIfcColourOrFactor( shared_ptr color_or_factor, vec4& src_color, vec4& target_color ) + { + // TYPE IfcColourOrFactor = SELECT ( IfcNormalisedRatioMeasure, IfcColourRgb); + shared_ptr color_rgb = dynamic_pointer_cast( color_or_factor ); + if( color_rgb ) + { + convertIfcColourRgb( color_rgb, target_color ); + return; + } + + shared_ptr ratio_measure = dynamic_pointer_cast( color_or_factor ); + if( ratio_measure ) + { + double factor = ratio_measure->m_value; + target_color.setColor( src_color.r()*factor, src_color.g()*factor, src_color.b()*factor, src_color.a() ); + return; + } + } + + void convertIfcColour( shared_ptr ifc_color_select, vec4& color ) + { + // IfcColour = SELECT ( IfcColourSpecification, IfcPreDefinedColour ); + shared_ptr color_spec = dynamic_pointer_cast( ifc_color_select ); + if( color_spec ) + { + // ENTITY IfcColourSpecification ABSTRACT SUPERTYPE OF(IfcColourRgb); + shared_ptr color_rgb = dynamic_pointer_cast( color_spec ); + if( color_rgb ) + { + convertIfcColourRgb( color_rgb, color ); + } + return; + } + + shared_ptr predefined_color = dynamic_pointer_cast( ifc_color_select ); + if( predefined_color ) + { + // ENTITY IfcPreDefinedColour ABSTRACT SUPERTYPE OF(IfcDraughtingPreDefinedColour) + shared_ptr draughting_predefined_color = dynamic_pointer_cast( predefined_color ); + if( draughting_predefined_color ) + { + if( draughting_predefined_color->m_Name ) + { + std::wstring predefined_name = draughting_predefined_color->m_Name->m_value; + if( boost::iequals( predefined_name, L"black" ) ) color.setColor( 0.0, 0.0, 0.0, 1.0 ); + else if( boost::iequals( predefined_name, L"red" ) ) color.setColor( 1.0, 0.0, 0.0, 1.0 ); + else if( boost::iequals( predefined_name, L"green" ) ) color.setColor( 0.0, 1.0, 0.0, 1.0 ); + else if( boost::iequals( predefined_name, L"blue" ) ) color.setColor( 0.0, 0.0, 1.0, 1.0 ); + else if( boost::iequals( predefined_name, L"yellow" ) ) color.setColor( 1.0, 1.0, 0.0, 1.0 ); + else if( boost::iequals( predefined_name, L"magenta" ) ) color.setColor( 1.0, 0.0, 1.0, 1.0 ); + else if( boost::iequals( predefined_name, L"cyan" ) ) color.setColor( 0.0, 1.0, 1.0, 1.0 ); + else if( boost::iequals( predefined_name, L"white" ) ) color.setColor( 1.0, 1.0, 1.0, 1.0 ); + } + } + return; + } + } + void convertIfcCurveStyle( shared_ptr curve_style, shared_ptr& appearance_data ) { if( !curve_style ) From 8bfc6d7eb813b28146f10d04c6757a99c5ed674a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B6ber?= Date: Fri, 20 Apr 2018 13:48:45 +0200 Subject: [PATCH 3/6] Change ConvertIfcComplexPropertyColor to return instead of void --- .../ifcpp/geometry/Carve/GeometryConverter.h | 7 +++---- .../src/ifcpp/geometry/StylesConverter.h | 17 ++++++----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryConverter.h b/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryConverter.h index 4bab7b346..a2c71c8f6 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryConverter.h @@ -237,15 +237,14 @@ class GeometryConverter : public StatusCallback continue; } - shared_ptr complex_property = dynamic_pointer_cast(ifc_property); + auto const complex_property = dynamic_pointer_cast(ifc_property); if( complex_property ) { if( !complex_property->m_UsageName ) continue; if( complex_property->m_UsageName->m_value.compare( L"Color" ) == 0 ) { - vec4 vec_color; - m_representation_converter->getStylesConverter()->convertIfcComplexPropertyColor( complex_property, vec_color ); - shared_ptr appearance_data( new AppearanceData( -1 ) ); + auto const vec_color = m_representation_converter->getStylesConverter()->convertIfcComplexPropertyColor( complex_property ); + auto appearance_data = std::make_shared( -1 ); if( !appearance_data ) { throw OutOfMemoryException( __FUNC__ ); diff --git a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h index 9e4109f39..fed572de4 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h @@ -354,13 +354,13 @@ class StylesConverter : public StatusCallback } } - void convertIfcComplexPropertyColor( shared_ptr complex_property, vec4& vec_color ) + vec4 convertIfcComplexPropertyColor( shared_ptr const& complex_property ) { std::vector >& vec_HasProperties = complex_property->m_HasProperties; - if( !complex_property->m_UsageName ) return; - if( vec_HasProperties.size() < 3 ) return; + if( !complex_property->m_UsageName ) return {}; + if( vec_HasProperties.size() < 3 ) return {}; std::wstring usage_name = complex_property->m_UsageName->m_value; - if( !boost::iequals( usage_name.c_str(), L"Color" ) ) return; + if( !boost::iequals( usage_name.c_str(), L"Color" ) ) return {}; if( complex_property->m_HasProperties.size() > 2 ) { @@ -391,11 +391,7 @@ class StylesConverter : public StatusCallback g = 0.12; b = 0.15; } - vec_color.m_r = r; - vec_color.m_g = g; - vec_color.m_b = b; - vec_color.m_a = 1.0; - + return { r, g, b, 1.0 }; #ifdef ENABLE_OPENMP //ScopedLock lock( m_writelock_styles_converter ); #endif @@ -405,12 +401,11 @@ class StylesConverter : public StatusCallback //appearance_data->shininess = 35.f; //m_map_ifc_styles[complex_property_id] = appearance_data; - - return; } } } } + return {}; } void convertIfcPresentationStyle( shared_ptr presentation_style, shared_ptr& appearance_data ) From f62a03235894ec9957efa37cf98a91017eac846e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B6ber?= Date: Fri, 20 Apr 2018 14:05:49 +0200 Subject: [PATCH 4/6] Change convertRepresentationStyle to return value instead of out parameter --- .../geometry/Carve/RepresentationConverter.h | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h b/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h index c08a0564f..95760b595 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h @@ -140,15 +140,17 @@ class RepresentationConverter : public StatusCallback m_face_converter->m_unit_converter = unit_converter; } - void convertRepresentationStyle( const shared_ptr& representation_item, std::vector >& vec_appearance_data ) + std::vector > convertRepresentationStyle( const shared_ptr& representation_item ) { std::vector >& vec_StyledByItem_inverse = representation_item->m_StyledByItem_inverse; + std::vector > vec_appearance_data; for( size_t i = 0; i < vec_StyledByItem_inverse.size(); ++i ) { weak_ptr styled_item_weak = vec_StyledByItem_inverse[i]; shared_ptr styled_item = shared_ptr( styled_item_weak ); m_styles_converter->convertIfcStyledItem( styled_item, vec_appearance_data ); } + return vec_appearance_data; } void convertIfcRepresentation( const shared_ptr& ifc_representation, shared_ptr& representation_data ) @@ -205,7 +207,7 @@ class RepresentationConverter : public StatusCallback { shared_ptr representation_item = ifc_representation->m_Items[i_representation_items]; - //ENTITY IfcRepresentationItem ABSTRACT SUPERTYPE OF(ONEOF(IfcGeometricRepresentationItem, IfcMappedItem, IfcStyledItem, IfcTopologicalRepresentationItem)); + //ENTITY IfcRepresentationItem ABSTRACT SUPERTYPE OF(ONEOF(IfcGeometricRepresentationItem, IfcMappedItem, IfcStyledItem, IfcTopologicalRepresentationItem)); shared_ptr geom_item = dynamic_pointer_cast( representation_item ); if( geom_item ) { @@ -300,8 +302,7 @@ class RepresentationConverter : public StatusCallback if( m_geom_settings->handleStyledItems() ) { - std::vector > vec_appearance_data; - convertRepresentationStyle( representation_item, vec_appearance_data ); + auto const vec_appearance_data = convertRepresentationStyle( representation_item ); if( vec_appearance_data.size() > 0 ) { @@ -313,7 +314,7 @@ class RepresentationConverter : public StatusCallback for( size_t jj_appearance = 0; jj_appearance < vec_appearance_data.size(); ++jj_appearance ) { - shared_ptr& data = vec_appearance_data[jj_appearance]; + auto const& data = vec_appearance_data[jj_appearance]; if( data ) { mapped_item_data->m_vec_item_appearances.push_back( data ); @@ -409,8 +410,7 @@ class RepresentationConverter : public StatusCallback //IfcSolidModel, IfcSurface, IfcTessellatedItem, IfcTextLiteral, IfcVector)) if( m_geom_settings->handleStyledItems() ) { - std::vector > vec_appearance_data; - convertRepresentationStyle( geom_item, vec_appearance_data ); + auto const vec_appearance_data = convertRepresentationStyle( geom_item ); std::copy( vec_appearance_data.begin(), vec_appearance_data.end(), std::back_inserter( item_data->m_vec_item_appearances ) ); } @@ -609,9 +609,9 @@ class RepresentationConverter : public StatusCallback shared_ptr text_literal = dynamic_pointer_cast( geom_item ); if( text_literal ) { - // Literal : IfcPresentableText; - // Placement : IfcAxis2Placement; - // Path : IfcTextPath; + // Literal : IfcPresentableText; + // Placement : IfcAxis2Placement; + // Path : IfcTextPath; if( m_geom_settings->isShowTextLiterals() ) { shared_ptr& ifc_literal = text_literal->m_Literal; @@ -715,7 +715,7 @@ class RepresentationConverter : public StatusCallback void convertTopologicalRepresentationItem( const shared_ptr& topological_item, shared_ptr topo_item_data ) { - //IfcTopologicalRepresentationItem ABSTRACT SUPERTYPE OF(ONEOF(IfcConnectedFaceSet, IfcEdge, IfcFace, IfcFaceBound, IfcLoop, IfcPath, IfcVertex)) + //IfcTopologicalRepresentationItem ABSTRACT SUPERTYPE OF(ONEOF(IfcConnectedFaceSet, IfcEdge, IfcFace, IfcFaceBound, IfcLoop, IfcPath, IfcVertex)) const shared_ptr topo_connected_face_set = dynamic_pointer_cast( topological_item ); if( topo_connected_face_set ) { @@ -761,9 +761,9 @@ class RepresentationConverter : public StatusCallback //shared_ptr topo_face_surface = dynamic_pointer_cast( topo_face ); //if( topo_face_surface ) //{ - // // std::vector > m_Bounds; - // // shared_ptr m_FaceSurface; - // // bool m_SameSense; + // // std::vector > m_Bounds; + // // shared_ptr m_FaceSurface; + // // bool m_SameSense; // const shared_ptr& face_surface = topo_face_surface->m_FaceSurface; // if( face_surface ) From b5a0fa6551fd557632f51f8d2313cd7d1a51b278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B6ber?= Date: Fri, 20 Apr 2018 14:34:38 +0200 Subject: [PATCH 5/6] Change convertIfcPresentationStyle to return shared pointer --- .../ifcpp/geometry/Carve/GeometryInputData.h | 2 +- .../geometry/Carve/RepresentationConverter.h | 3 +-- .../src/ifcpp/geometry/StylesConverter.h | 18 +++++++++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryInputData.h b/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryInputData.h index 9edb95020..01311d588 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryInputData.h +++ b/IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryInputData.h @@ -471,7 +471,7 @@ class RepresentationData std::copy( other->m_vec_representation_appearances.begin(), other->m_vec_representation_appearances.end(), std::back_inserter( m_vec_representation_appearances ) ); } - void addAppearance( shared_ptr& appearance ) + void addAppearance( shared_ptr const& appearance ) { if( !appearance ) { diff --git a/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h b/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h index 95760b595..440ce6f04 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h @@ -387,8 +387,7 @@ class RepresentationConverter : public StatusCallback shared_ptr& presentation_style = vec_presentation_styles[ii_style]; if( presentation_style ) { - shared_ptr appearance_data; - m_styles_converter->convertIfcPresentationStyle( presentation_style, appearance_data ); + auto const appearance_data = m_styles_converter->convertIfcPresentationStyle( presentation_style ); if( appearance_data ) { representation_data->addAppearance( appearance_data ); diff --git a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h index fed572de4..933b3c191 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h @@ -342,8 +342,7 @@ class StylesConverter : public StatusCallback shared_ptr presentation_style = dynamic_pointer_cast( style_assign_select ); if( presentation_style ) { - shared_ptr appearance_data; - convertIfcPresentationStyle( presentation_style, appearance_data ); + auto const appearance_data = convertIfcPresentationStyle( presentation_style ); if( appearance_data ) { vec_appearance_data.push_back( appearance_data ); @@ -408,9 +407,10 @@ class StylesConverter : public StatusCallback return {}; } - void convertIfcPresentationStyle( shared_ptr presentation_style, shared_ptr& appearance_data ) + shared_ptr convertIfcPresentationStyle( shared_ptr presentation_style ) { int style_id = presentation_style->m_entity_id; + shared_ptr appearance_data; auto it_find_existing_style = m_map_ifc_styles.find( style_id ); if( it_find_existing_style != m_map_ifc_styles.end() ) { @@ -418,7 +418,7 @@ class StylesConverter : public StatusCallback appearance_data = it_find_existing_style->second; if( appearance_data->m_complete ) { - return; + return appearance_data; } } else @@ -438,7 +438,7 @@ class StylesConverter : public StatusCallback if( curve_style ) { convertIfcCurveStyle( curve_style, appearance_data ); - return; + return appearance_data; } shared_ptr fill_area_style = dynamic_pointer_cast( presentation_style ); @@ -447,14 +447,14 @@ class StylesConverter : public StatusCallback #ifdef _DEBUG std::cout << "IfcFillAreaStyle not implemented" << std::endl; #endif - return; + return appearance_data; } shared_ptr surface_style = dynamic_pointer_cast( presentation_style ); if( surface_style ) { convertIfcSurfaceStyle( surface_style, appearance_data ); - return; + return appearance_data; } shared_ptr text_style = dynamic_pointer_cast( presentation_style ); @@ -462,10 +462,10 @@ class StylesConverter : public StatusCallback { appearance_data->m_text_style = text_style; appearance_data->m_complete = true; - return; + return appearance_data; } - return; + return appearance_data; } private: From 621b1cf5e88ab03dff710896c32f13bb126a2d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B6ber?= Date: Fri, 20 Apr 2018 15:19:33 +0200 Subject: [PATCH 6/6] Change StylesConverter towards more usage of auto. --- .../src/ifcpp/geometry/StylesConverter.h | 124 ++++++++---------- 1 file changed, 55 insertions(+), 69 deletions(-) diff --git a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h index 933b3c191..238632046 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/StylesConverter.h @@ -247,11 +247,10 @@ class StylesConverter : public StatusCallback void convertIfcStyledItem( weak_ptr styled_item_weak, std::vector >& vec_appearance_data ) { if( styled_item_weak.expired() ) - { return; - } - shared_ptr styled_item( styled_item_weak ); - const int style_id = styled_item->m_entity_id; + + auto const styled_item = styled_item_weak.lock(); + auto const style_id = styled_item->m_entity_id; auto it_find_existing_style = m_map_ifc_styles.find( style_id ); if( it_find_existing_style != m_map_ifc_styles.end() ) @@ -260,54 +259,46 @@ class StylesConverter : public StatusCallback return; } - std::vector >& vec_style_assigns = styled_item->m_Styles; - for( size_t i_style_assign = 0; i_style_assign < vec_style_assigns.size(); ++i_style_assign ) + auto const& vec_style_assigns = styled_item->m_Styles; + for( auto const& style_assign_select : vec_style_assigns ) { // TYPE IfcStyleAssignmentSelect = SELECT (IfcPresentationStyle ,IfcPresentationStyleAssignment); - shared_ptr style_assign_select = vec_style_assigns[i_style_assign]; if( !style_assign_select ) - { continue; - } - shared_ptr presentation_style_assign = dynamic_pointer_cast( style_assign_select ); + auto const presentation_style_assign = dynamic_pointer_cast( style_assign_select ); if( presentation_style_assign ) { - std::vector >& vec_styles = presentation_style_assign->m_Styles; - for( size_t i_presentation_style = 0; i_presentation_style < vec_styles.size(); ++i_presentation_style ) + auto const& vec_styles = presentation_style_assign->m_Styles; + for( auto const& presentation_style_select : vec_styles ) { // TYPE IfcPresentationStyleSelect = SELECT (IfcCurveStyle ,IfcFillAreaStyle ,IfcNullStyle ,IfcSurfaceStyle ,IfcSymbolStyle ,IfcTextStyle); - shared_ptr presentation_style_select = vec_styles[i_presentation_style]; shared_ptr appearance_data; - shared_ptr curve_style = dynamic_pointer_cast( presentation_style_select ); + auto const curve_style = dynamic_pointer_cast( presentation_style_select ); if( curve_style ) { convertIfcCurveStyle( curve_style, appearance_data ); if( appearance_data ) - { vec_appearance_data.push_back( appearance_data ); - } continue; } - shared_ptr surface_style = dynamic_pointer_cast( presentation_style_select ); + auto const surface_style = dynamic_pointer_cast( presentation_style_select ); if( surface_style ) { convertIfcSurfaceStyle( surface_style, appearance_data ); if( appearance_data ) - { vec_appearance_data.push_back( appearance_data ); - } continue; } - shared_ptr text_style = dynamic_pointer_cast( presentation_style_select ); + auto const text_style = dynamic_pointer_cast( presentation_style_select ); if( text_style ) { if( !appearance_data ) { - int text_style_id = text_style->m_entity_id; - appearance_data = shared_ptr( new AppearanceData( text_style_id ) ); + auto const text_style_id = text_style->m_entity_id; + appearance_data = std::make_shared( text_style_id ); } appearance_data->m_text_style = text_style; @@ -317,7 +308,7 @@ class StylesConverter : public StatusCallback continue; } - shared_ptr fill_area_style = dynamic_pointer_cast( presentation_style_select ); + auto const fill_area_style = dynamic_pointer_cast( presentation_style_select ); if( fill_area_style ) { #ifdef _DEBUG @@ -326,7 +317,7 @@ class StylesConverter : public StatusCallback continue; } - shared_ptr null_style = dynamic_pointer_cast( presentation_style_select ); + auto const null_style = dynamic_pointer_cast( presentation_style_select ); if( null_style ) { #ifdef _DEBUG @@ -339,7 +330,7 @@ class StylesConverter : public StatusCallback } // ENTITY IfcPresentationStyle ABSTRACT SUPERTYPE OF(ONEOF(IfcCurveStyle, IfcFillAreaStyle, IfcSurfaceStyle, IfcSymbolStyle, IfcTextStyle)); - shared_ptr presentation_style = dynamic_pointer_cast( style_assign_select ); + auto const presentation_style = dynamic_pointer_cast( style_assign_select ); if( presentation_style ) { auto const appearance_data = convertIfcPresentationStyle( presentation_style ); @@ -355,28 +346,28 @@ class StylesConverter : public StatusCallback vec4 convertIfcComplexPropertyColor( shared_ptr const& complex_property ) { - std::vector >& vec_HasProperties = complex_property->m_HasProperties; + auto const& vec_HasProperties = complex_property->m_HasProperties; if( !complex_property->m_UsageName ) return {}; if( vec_HasProperties.size() < 3 ) return {}; - std::wstring usage_name = complex_property->m_UsageName->m_value; + auto const& usage_name = complex_property->m_UsageName->m_value; if( !boost::iequals( usage_name.c_str(), L"Color" ) ) return {}; if( complex_property->m_HasProperties.size() > 2 ) { - shared_ptr prop1 = dynamic_pointer_cast( complex_property->m_HasProperties[0] ); - shared_ptr prop2 = dynamic_pointer_cast( complex_property->m_HasProperties[1] ); - shared_ptr prop3 = dynamic_pointer_cast( complex_property->m_HasProperties[2] ); + auto const prop1 = dynamic_pointer_cast( complex_property->m_HasProperties[0] ); + auto const prop2 = dynamic_pointer_cast( complex_property->m_HasProperties[1] ); + auto const prop3 = dynamic_pointer_cast( complex_property->m_HasProperties[2] ); if( prop1 && prop2 && prop3 ) { - shared_ptr v1_select = prop1->m_NominalValue; - shared_ptr v2_select = prop2->m_NominalValue; - shared_ptr v3_select = prop3->m_NominalValue; + auto const& v1_select = prop1->m_NominalValue; + auto const& v2_select = prop2->m_NominalValue; + auto const& v3_select = prop3->m_NominalValue; if( v1_select && v2_select && v3_select ) { - shared_ptr v1_int = dynamic_pointer_cast( v1_select ); - shared_ptr v2_int = dynamic_pointer_cast( v2_select ); - shared_ptr v3_int = dynamic_pointer_cast( v3_select ); + auto const v1_int = dynamic_pointer_cast( v1_select ); + auto const v2_int = dynamic_pointer_cast( v2_select ); + auto const v3_int = dynamic_pointer_cast( v3_select ); if( v1_int && v2_int && v3_int ) { @@ -407,9 +398,9 @@ class StylesConverter : public StatusCallback return {}; } - shared_ptr convertIfcPresentationStyle( shared_ptr presentation_style ) + shared_ptr convertIfcPresentationStyle( shared_ptr const& presentation_style ) { - int style_id = presentation_style->m_entity_id; + auto const style_id = presentation_style->m_entity_id; shared_ptr appearance_data; auto it_find_existing_style = m_map_ifc_styles.find( style_id ); if( it_find_existing_style != m_map_ifc_styles.end() ) @@ -425,7 +416,7 @@ class StylesConverter : public StatusCallback { if( !appearance_data ) { - appearance_data = shared_ptr( new AppearanceData( style_id ) ); + appearance_data = std::make_shared( style_id ); } #ifdef ENABLE_OPENMP ScopedLock lock( m_writelock_styles_converter ); @@ -434,14 +425,14 @@ class StylesConverter : public StatusCallback } // ENTITY IfcPresentationStyle ABSTRACT SUPERTYPE OF(ONEOF(IfcCurveStyle, IfcFillAreaStyle, IfcSurfaceStyle, IfcSymbolStyle, IfcTextStyle)); - shared_ptr curve_style = dynamic_pointer_cast( presentation_style ); + auto const curve_style = dynamic_pointer_cast( presentation_style ); if( curve_style ) { convertIfcCurveStyle( curve_style, appearance_data ); return appearance_data; } - shared_ptr fill_area_style = dynamic_pointer_cast( presentation_style ); + auto const fill_area_style = dynamic_pointer_cast( presentation_style ); if( fill_area_style ) { #ifdef _DEBUG @@ -450,14 +441,14 @@ class StylesConverter : public StatusCallback return appearance_data; } - shared_ptr surface_style = dynamic_pointer_cast( presentation_style ); + auto const surface_style = dynamic_pointer_cast( presentation_style ); if( surface_style ) { convertIfcSurfaceStyle( surface_style, appearance_data ); return appearance_data; } - shared_ptr text_style = dynamic_pointer_cast( presentation_style ); + auto const text_style = dynamic_pointer_cast( presentation_style ); if( text_style ) { appearance_data->m_text_style = text_style; @@ -469,63 +460,61 @@ class StylesConverter : public StatusCallback } private: - void convertIfcSpecularHighlightSelect( shared_ptr highlight_select, shared_ptr& appearance_data ) + void convertIfcSpecularHighlightSelect( shared_ptr const& highlight_select, shared_ptr& appearance_data ) { - if( dynamic_pointer_cast( highlight_select ) ) + if( auto const spec = dynamic_pointer_cast( highlight_select ) ) { - shared_ptr spec = dynamic_pointer_cast( highlight_select ); appearance_data->m_specular_exponent = spec->m_value; } - else if( dynamic_pointer_cast( highlight_select ) ) + else if( auto const specular_roughness = dynamic_pointer_cast( highlight_select ) ) { - shared_ptr specular_roughness = dynamic_pointer_cast( highlight_select ); appearance_data->m_specular_roughness = specular_roughness->m_value; } } - void convertIfcColourRgb( shared_ptr color_rgb, vec4& color ) + void convertIfcColourRgb( shared_ptr const& color_rgb, vec4& color ) { if( color_rgb->m_Red ) { - color.m_r = (float)color_rgb->m_Red->m_value; + color.m_r = color_rgb->m_Red->m_value; } if( color_rgb->m_Green ) { - color.m_g = (float)color_rgb->m_Green->m_value; + color.m_g = color_rgb->m_Green->m_value; } if( color_rgb->m_Blue ) { - color.m_b = (float)color_rgb->m_Blue->m_value; + color.m_b = color_rgb->m_Blue->m_value; } } - void convertIfcColourOrFactor( shared_ptr color_or_factor, vec4& src_color, vec4& target_color ) + void convertIfcColourOrFactor( shared_ptr const& color_or_factor, vec4& src_color, vec4& target_color ) { // TYPE IfcColourOrFactor = SELECT ( IfcNormalisedRatioMeasure, IfcColourRgb); - shared_ptr color_rgb = dynamic_pointer_cast( color_or_factor ); + auto const color_rgb = dynamic_pointer_cast( color_or_factor ); if( color_rgb ) { convertIfcColourRgb( color_rgb, target_color ); return; } - shared_ptr ratio_measure = dynamic_pointer_cast( color_or_factor ); + auto const ratio_measure = dynamic_pointer_cast( color_or_factor ); if( ratio_measure ) { - double factor = ratio_measure->m_value; + auto const& factor = ratio_measure->m_value; target_color.setColor( src_color.r()*factor, src_color.g()*factor, src_color.b()*factor, src_color.a() ); return; } } - void convertIfcColour( shared_ptr ifc_color_select, vec4& color ) + void convertIfcColour( shared_ptr const& ifc_color_select, vec4& color ) { // IfcColour = SELECT ( IfcColourSpecification, IfcPreDefinedColour ); - shared_ptr color_spec = dynamic_pointer_cast( ifc_color_select ); + auto const color_spec = dynamic_pointer_cast( ifc_color_select ); if( color_spec ) { // ENTITY IfcColourSpecification ABSTRACT SUPERTYPE OF(IfcColourRgb); - shared_ptr color_rgb = dynamic_pointer_cast( color_spec ); + auto const color_rgb = dynamic_pointer_cast( color_spec ); if( color_rgb ) { convertIfcColourRgb( color_rgb, color ); @@ -533,16 +522,16 @@ class StylesConverter : public StatusCallback return; } - shared_ptr predefined_color = dynamic_pointer_cast( ifc_color_select ); + auto const predefined_color = dynamic_pointer_cast( ifc_color_select ); if( predefined_color ) { // ENTITY IfcPreDefinedColour ABSTRACT SUPERTYPE OF(IfcDraughtingPreDefinedColour) - shared_ptr draughting_predefined_color = dynamic_pointer_cast( predefined_color ); + auto const draughting_predefined_color = dynamic_pointer_cast( predefined_color ); if( draughting_predefined_color ) { if( draughting_predefined_color->m_Name ) { - std::wstring predefined_name = draughting_predefined_color->m_Name->m_value; + auto const& predefined_name = draughting_predefined_color->m_Name->m_value; if( boost::iequals( predefined_name, L"black" ) ) color.setColor( 0.0, 0.0, 0.0, 1.0 ); else if( boost::iequals( predefined_name, L"red" ) ) color.setColor( 1.0, 0.0, 0.0, 1.0 ); else if( boost::iequals( predefined_name, L"green" ) ) color.setColor( 0.0, 1.0, 0.0, 1.0 ); @@ -557,21 +546,18 @@ class StylesConverter : public StatusCallback } } - void convertIfcCurveStyle( shared_ptr curve_style, shared_ptr& appearance_data ) + void convertIfcCurveStyle( shared_ptr const& curve_style, shared_ptr& appearance_data ) { if( !curve_style ) - { return; - } - int style_id = curve_style->m_entity_id; + + auto const style_id = curve_style->m_entity_id; auto it_find_existing_style = m_map_ifc_styles.find( style_id ); if( it_find_existing_style != m_map_ifc_styles.end() ) { appearance_data = it_find_existing_style->second; if( appearance_data->m_complete ) - { return; - } } else { @@ -590,7 +576,7 @@ class StylesConverter : public StatusCallback //CurveWidth : OPTIONAL IfcSizeSelect; //CurveColour : OPTIONAL IfcColour; - shared_ptr curve_color = curve_style->m_CurveColour; + auto const& curve_color = curve_style->m_CurveColour; if( curve_color ) { vec4 color( 0.2, 0.25, 0.3, 1.0 );