Title: svg serializing misses a representation that consists of just a circle · Issue #4283 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: svg serializing misses a representation that consists of just a circle · Issue #4283 · IfcOpenShell/IfcOpenShell
X Title: svg serializing misses a representation that consists of just a circle · Issue #4283 · IfcOpenShell/IfcOpenShell
Description: Noticed that svg drawing was missing a representation (Body/Plan/PLAN_VIEW) that consist of just 1 IfcCircle. In the file below it's representation #941. I've tried to narrow it down and noticed that if you add a rectangle (IfcIndexedPol...
Open Graph Description: Noticed that svg drawing was missing a representation (Body/Plan/PLAN_VIEW) that consist of just 1 IfcCircle. In the file below it's representation #941. I've tried to narrow it down and noticed th...
X Description: Noticed that svg drawing was missing a representation (Body/Plan/PLAN_VIEW) that consist of just 1 IfcCircle. In the file below it's representation #941. I've tried to narrow it down and no...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/4283
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"svg serializing misses a representation that consists of just a circle","articleBody":"Noticed that svg drawing was missing a representation (Body/Plan/PLAN_VIEW) that consist of just 1 IfcCircle. In the file below it's representation `#941`. \r\n\r\nI've tried to narrow it down and noticed that if you add a rectangle (`IfcIndexedPolyCurve`) to the representation's items it prints both circle and rectangle.\r\n\r\nScript and example file are below. Script is expecting a path to the `trees.ifc` at the end of the code and it prints svg generated for the representation `#941`. At the end of the code you can notice that I've added a rectangle to the representation `rep.Items = [rectangle, circle]` to make it work and commented it out, you can uncomment it for tests.\r\n\r\n[trees.ifc.txt](https://github.com/IfcOpenShell/IfcOpenShell/files/14125404/trees.ifc.txt)\r\n\r\n\r\n```python\r\nimport ifcopenshell\r\nimport ifcopenshell.geom\r\nimport multiprocessing\r\nfrom mathutils import Vector\r\nfrom collections import namedtuple\r\nfrom pathlib import Path\r\nfrom pprint import pprint\r\n\r\nLineworkContexts = namedtuple(\r\n \"LineworkContexts\",\r\n (\r\n \"plan_body_target plan_body_model model_body_target model_body_model plan_annotation_target \"\r\n \"plan_annotation_model model_annotation_target model_annotation_model\"\r\n ),\r\n)\r\n\r\n\r\nclass SvgWriter:\r\n def __init__(\r\n self,\r\n ifc_filepath: Path,\r\n ifc_file: ifcopenshell.file,\r\n drawing,\r\n drawing_document,\r\n drawing_elements: set[ifcopenshell.entity_instance],\r\n ):\r\n self.camera_element = drawing\r\n self.camera_document = drawing_document\r\n self.file = ifc_file\r\n self.drawing_elements = drawing_elements\r\n self.ifc_filepath = ifc_filepath\r\n\r\n # hardcoded\r\n self.scale = 0.01\r\n self.human_scale = \"1:100\"\r\n self.camera_width, self.camera_height = 50, 50\r\n\r\n self.drawing = drawing\r\n self.drawing_name = self.drawing.Name\r\n\r\n self.generate_linework()\r\n\r\n def get_linework_contexts(self, ifc, target_view) -> LineworkContexts:\r\n contexts = LineworkContexts(*[[] for _ in range(len(LineworkContexts._fields))])\r\n\r\n for rep_context in ifc.by_type(\"IfcGeometricRepresentationContext\"):\r\n if rep_context.is_a(\"IfcGeometricRepresentationSubContext\"):\r\n if rep_context.ContextType == \"Plan\":\r\n if rep_context.ContextIdentifier in [\"Body\", \"Facetation\"]:\r\n if rep_context.TargetView == target_view:\r\n contexts.plan_body_target.append(rep_context.id())\r\n elif rep_context.TargetView == \"MODEL_VIEW\":\r\n contexts.plan_body_model.append(rep_context.id())\r\n elif rep_context.ContextIdentifier == \"Annotation\":\r\n if rep_context.TargetView == target_view:\r\n contexts.plan_annotation_target.append(rep_context.id())\r\n elif rep_context.TargetView == \"MODEL_VIEW\":\r\n contexts.plan_annotation_model.append(rep_context.id())\r\n elif rep_context.ContextType == \"Model\":\r\n if rep_context.ContextIdentifier in [\"Body\", \"Facetation\"]:\r\n if rep_context.TargetView == target_view:\r\n contexts.model_body_target.append(rep_context.id())\r\n elif rep_context.TargetView == \"MODEL_VIEW\":\r\n contexts.model_body_model.append(rep_context.id())\r\n elif rep_context.ContextIdentifier == \"Annotation\":\r\n if rep_context.TargetView == target_view:\r\n contexts.model_annotation_target.append(rep_context.id())\r\n elif rep_context.TargetView == \"MODEL_VIEW\":\r\n contexts.model_annotation_model.append(rep_context.id())\r\n elif rep_context.ContextType == \"Model\":\r\n # You should never purely assign to a \"Model\" context, but\r\n # if you do, this is what we assume your intention is.\r\n contexts.model_body_model.append(rep_context.id())\r\n continue\r\n\r\n return contexts\r\n\r\n def process_contexts_elements(self, ifc, tree: ifcopenshell.geom.tree, contexts, drawing_elements, target_view):\r\n drawing_elements = self.drawing_elements.copy()\r\n for context in contexts:\r\n if not context or not drawing_elements:\r\n return\r\n geom_settings = ifcopenshell.geom.settings(\r\n DISABLE_TRIANGULATION=True, STRICT_TOLERANCE=True, INCLUDE_CURVES=True\r\n )\r\n if ifc.by_id(context[0]).ContextType == \"Plan\" and \"PLAN_VIEW\" in target_view:\r\n offset = ifcopenshell.ifcopenshell_wrapper.float_array_3()\r\n # A 2mm Z offset to combat Z-fighting in plan or RCPs\r\n offset[2] = 0 if target_view == \"PLAN_VIEW\" else -0\r\n geom_settings.offset = offset\r\n geom_settings.set_context_ids(context)\r\n it = ifcopenshell.geom.iterator(geom_settings, ifc, multiprocessing.cpu_count(), include=drawing_elements)\r\n processed = set()\r\n # TODO: replaced with iter\r\n for elem in it:\r\n print(f\"{elem.id} was drawn using contexts {context} ({ifc[context[0]]})\")\r\n processed.add(ifc.by_id(elem.id))\r\n self.serialiser.write(elem)\r\n tree.add_element(elem)\r\n drawing_elements -= processed\r\n\r\n def finalize(self, and_exit=False) -> str:\r\n self.serialiser.finalize()\r\n final_svg = self.svg_buffer.get_value()\r\n if and_exit:\r\n print(final_svg)\r\n exit()\r\n return final_svg\r\n\r\n def generate_linework(self):\r\n if not ifcopenshell.util.element.get_pset(self.drawing, \"EPset_Drawing\", \"HasLinework\"):\r\n return\r\n ifc = self.file\r\n\r\n target_view = ifcopenshell.util.element.get_psets(self.camera_element)[\"EPset_Drawing\"][\"TargetView\"]\r\n # Get all representation contexts to see what we're dealing with.\r\n # Drawings only draw bodies and annotations (and facetation, due to a Revit bug).\r\n # A drawing prioritises a target view context first, followed by a model view context as a fallback.\r\n # Specifically for PLAN_VIEW and REFLECTED_PLAN_VIEW, any Plan context is also prioritised.\r\n contexts = self.get_linework_contexts(ifc, target_view)\r\n\r\n body_contexts = (\r\n [\r\n contexts.plan_body_target,\r\n contexts.plan_body_model,\r\n contexts.model_body_target,\r\n contexts.model_body_model,\r\n ]\r\n if target_view in [\"PLAN_VIEW\", \"REFLECTED_PLAN_VIEW\"]\r\n else [\r\n contexts.model_body_target,\r\n contexts.model_body_model,\r\n ]\r\n )\r\n\r\n annotation_contexts = (\r\n [\r\n contexts.plan_annotation_target,\r\n contexts.plan_annotation_model,\r\n contexts.model_annotation_target,\r\n contexts.model_annotation_model,\r\n ]\r\n if target_view in [\"PLAN_VIEW\", \"REFLECTED_PLAN_VIEW\"]\r\n else [\r\n contexts.model_annotation_target,\r\n contexts.model_annotation_model,\r\n ]\r\n )\r\n\r\n drawing_elements = self.drawing_elements\r\n\r\n self.setup_serialiser(ifc, target_view)\r\n tree = ifcopenshell.geom.tree()\r\n tree.enable_face_styles(True)\r\n\r\n print(\"Drawing body contexts...\")\r\n print(body_contexts)\r\n self.process_contexts_elements(ifc, tree, body_contexts, drawing_elements, target_view)\r\n print(\"Drawing annotation contexts...\")\r\n print(annotation_contexts)\r\n self.process_contexts_elements(ifc, tree, annotation_contexts, drawing_elements, target_view)\r\n\r\n if self.camera_element not in drawing_elements:\r\n # The camera must always be included, regardless of any include/exclude filters.\r\n geom_settings = ifcopenshell.geom.settings(DISABLE_TRIANGULATION=True, STRICT_TOLERANCE=True)\r\n it = ifcopenshell.geom.iterator(geom_settings, ifc, include=[self.camera_element])\r\n for elem in it:\r\n self.serialiser.write(elem)\r\n self.finalize(True)\r\n\r\n def setup_serialiser(self, ifc, target_view):\r\n self.svg_settings = ifcopenshell.geom.settings(\r\n DISABLE_TRIANGULATION=True, STRICT_TOLERANCE=True, INCLUDE_CURVES=True\r\n )\r\n self.svg_buffer = ifcopenshell.geom.serializers.buffer()\r\n self.serialiser = ifcopenshell.geom.serializers.svg(self.svg_buffer, self.svg_settings)\r\n self.serialiser.setFile(ifc)\r\n self.serialiser.setWithoutStoreys(True)\r\n self.serialiser.setPolygonal(True)\r\n self.serialiser.setUseHlrPoly(True)\r\n # Objects with more than these edges are rendered as wireframe instead of HLR for optimisation\r\n self.serialiser.setProfileThreshold(10000)\r\n self.serialiser.setUseNamespace(True)\r\n self.serialiser.setAlwaysProject(True)\r\n self.serialiser.setAutoElevation(False)\r\n self.serialiser.setAutoSection(False)\r\n self.serialiser.setPrintSpaceNames(False)\r\n self.serialiser.setPrintSpaceAreas(False)\r\n self.serialiser.setDrawDoorArcs(False)\r\n self.serialiser.setNoCSS(True)\r\n self.serialiser.setElevationRefGuid(self.camera_element.GlobalId)\r\n self.serialiser.setScale(self.scale)\r\n self.serialiser.setSubtractionSettings(ifcopenshell.ifcopenshell_wrapper.ALWAYS)\r\n self.serialiser.setUsePrefiltering(True) # See #3359\r\n self.serialiser.setUnifyInputs(True)\r\n self.serialiser.setSegmentProjection(True)\r\n if target_view == \"REFLECTED_PLAN_VIEW\":\r\n self.serialiser.setMirrorY(True)\r\n # tree = ifcopenshell.geom.tree()\r\n # This instructs the tree to explode BReps into faces and return\r\n # the style of the face when running tree.select_ray()\r\n # tree.enable_face_styles(True)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n filepath = Path(r\"trees.ifc\")\r\n ifc_file = ifcopenshell.open(filepath)\r\n # 1356=IfcAnnotation('3MZReDReH6JhO_xt9TCAyc',$,'PLAN_VIEW',$,'DRAWING',#1361,#1367)\r\n drawing = ifc_file.by_id(1356)\r\n # 1387=IfcDocumentReference('drawings/PLAN_VIEW.svg',$,$,$,#1385)\r\n drawing_document = ifc_file.by_id(1387)\r\n drawing_elements = {1301}\r\n drawing_elements = {ifc_file.by_id(i) for i in drawing_elements}\r\n\r\n from ifcopenshell.util.shape_builder import ShapeBuilder\r\n builder = ShapeBuilder(ifc_file)\r\n rep = ifc_file.by_id(941)\r\n circle = rep.Items[0]\r\n radius = circle.Radius\r\n size = Vector((radius, radius)) * 2\r\n rectangle = builder.rectangle(size=size, position=-size/2)\r\n rep.Items = [circle] # empty .svg\r\n # rep.Items = [rectangle] # .svg contains a square\r\n # rep.Items = [rectangle, circle] # .svg contains a square and circle\r\n\r\n SvgWriter(filepath, ifc_file, drawing, drawing_document, drawing_elements)\r\n\r\n```","author":{"url":"https://github.com/Andrej730","@type":"Person","name":"Andrej730"},"datePublished":"2024-02-01T12:50:01Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/4283"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:19950ffd-98cc-e4cb-1656-bfd4a9c462cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EA60:259D98:8FDEA5:C46E78:6B047EE6 |
| html-safe-nonce | 1580c55306f95d22f063491569a911002b20f18e69fd28c51d05c2743ea0cfac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTYwOjI1OUQ5ODo4RkRFQTU6QzQ2RTc4OjZCMDQ3RUU2IiwidmlzaXRvcl9pZCI6IjYyNjYyMjQzNDQ1MzY3NDM2NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0093d1c49a62348a73a3523c32dad52635363e10464ec19a3940bd510b0be1bb |
| hovercard-subject-tag | issue:2112444580 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/4283/issue_layout |
| twitter:image | https://opengraph.githubassets.com/709018132e2b8edf10a3a928c2524ba4916afc276615fcb76573971db6fb09af/IfcOpenShell/IfcOpenShell/issues/4283 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/709018132e2b8edf10a3a928c2524ba4916afc276615fcb76573971db6fb09af/IfcOpenShell/IfcOpenShell/issues/4283 |
| og:image:alt | Noticed that svg drawing was missing a representation (Body/Plan/PLAN_VIEW) that consist of just 1 IfcCircle. In the file below it's representation #941. I've tried to narrow it down and noticed th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Andrej730 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0366ddfb372682a32e92a5d86155cb08fa83e5bbe79953a968789f2f7e24c511 |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ed3f2e01f6b7672780c586c8af0e72726374d7b6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width