Skip to content

Commit

Permalink
Merge pull request #71 from 3MFConsortium/3djan/implicit_improvements
Browse files Browse the repository at this point in the history
Improvements to the volumetric spec
  • Loading branch information
3dJan authored Aug 5, 2024
2 parents efa3a13 + ad3af0d commit 6497051
Show file tree
Hide file tree
Showing 10 changed files with 1,876 additions and 1,459 deletions.
1,419 changes: 774 additions & 645 deletions 3MF Volumetric Extension Template.md

Large diffs are not rendered by default.

1,750 changes: 941 additions & 809 deletions 3MF Volumetric Extension.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
with open(f'{cwd}/3MF Volumetric Extension Template.md', 'r') as file:
template = file.read()

implict = None
implicit = None
with open(f'{cwd}/implicit.xsd', 'r') as file:
implicit = file.read()

Expand Down
140 changes: 140 additions & 0 deletions apply_prefixes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import re
import sys

def change_namespace_prefix_md(md_file, elements, new_prefix):
# Read the Markdown file
with open(md_file, 'r') as f:
content = f.read()

# Find XML snippets
snippets = re.findall(r'```xml(.*?)```', content, re.DOTALL)

for snippet in snippets:
original_snippet = snippet
print (f"Snippet: {snippet}")
# Replace the namespace prefix in the XML snippet
for element in elements:
snippet = re.sub(rf'<{element} ', f'<{new_prefix}:{element} ', snippet, flags=re.IGNORECASE)
snippet = re.sub(rf'</{element}>', f'</{new_prefix}:{element}>', snippet, flags=re.IGNORECASE)
snippet = re.sub(rf'<{element}>', f'<{new_prefix}:{element}>', snippet, flags=re.IGNORECASE)
snippet = re.sub(rf'</{element} ', f'</{new_prefix}:{element} ', snippet, flags=re.IGNORECASE)



print (f"New snippet: {snippet}")
print("-" * 80)
# Replace the original XML snippet with the modified one
content = content.replace(original_snippet, f'\n{snippet}\n')

# Write the modified Markdown back to the file
with open(md_file, 'w') as f:
f.write(content)

f.close()

def change_namespace_prefix_md_from_file(md_file, elements_file, new_prefix):
# Read the elements file
with open(elements_file, 'r') as f:
elements = [line.strip() for line in f]

change_namespace_prefix_md(md_file, elements, new_prefix)

def apply_implicit_prefix(md_file):
prefix = "i"
elements = [
"implicitfunction",
"scalar",
"vector",
"matrix",
"resourceid",
"in",
"out",
"scalarref",
"vectorref",
"matrixref",
"resourceref",
"addition",
"subtraction",
"multiplication",
"division",
"constant",
"constvec",
"constmat",
"composevector",
"vectorfromscalar",
"decomposevector",
"composematrix",
"matrixfromcolumns",
"matrixfromrows",
"dot",
"cross",
"matvecmultiplication",
"transpose",
"inverse",
"sin",
"cos",
"tan",
"arcsin",
"arccos",
"arctan",
"arctan2",
"min",
"max",
"abs",
"fmod",
"pow",
"sqrt",
"exp",
"log",
"log2",
"log10",
"select",
"clamp",
"cosh",
"sinh",
"tanh",
"round",
"ceil",
"floor",
"sign",
"fract",
"functioncall",
"unsignedmesh",
"length",
"constresourceid",
"mod"
]

change_namespace_prefix_md(md_file, elements, prefix)

def apply_volumetric_prefix(md_file):
prefix = "v"
elements = [
"image3d",
"imagestack",
"imagesheet",
"functionfromimage3d",
"volumedata",
"composite",
"materialmapping",
"color",
"property",
"levelset"
]

change_namespace_prefix_md(md_file, elements, prefix)

def apply_prefixes(md_file):
apply_implicit_prefix(md_file)
#apply_volumetric_prefix(md_file)

if __name__ == "__main__":
if len(sys.argv) < 1:
print("Usage: python apply_prefixes.py md_file")
# print number of arguments
print(len(sys.argv))
sys.exit(1)

md_file = sys.argv[1]

apply_prefixes(md_file)
17 changes: 17 additions & 0 deletions format_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import re

# Read the content of the markdown file
with open('3MF Volumetric Extension Template.md', 'r', encoding='utf-8') as file:
content = file.read()

# Define a regular expression pattern to match any XML tag starting with a backslash, excluding those enclosed in ** **
pattern = r'(?<!\*\*)\\<([\w]+)>(?!\*\*)'

# Replace the matched XML tags with the desired format
modified_content = re.sub(pattern, r'`<\1>`', content)

# Write the modified content back to the file
with open('3MF Volumetric Extension Template.md', 'w', encoding='utf-8') as file:
file.write(modified_content)

print("XML tags starting with a backslash have been replaced successfully, excluding those enclosed in ** **.")
Binary file modified images/element_functionformimage3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sphere_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions implicit.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@
<![CDATA[
Node for evaluating the unsigned distance to a mesh. The input must have the identifier "pos" and must be a vector. The output is a scalar and must have the identifier "distance".
The mesh is defined by a resource identifier. The mesh may be be open and is not required to be watertight.
The distance is positive if the point is outside the mesh and negative if the point is inside the mesh.
The distance is always positive.
Example:
<unsignedmesh identifier="UnsigendDistanceToMesh1" displayname="Unsigned Distance to Mesh 1">
Expand Down Expand Up @@ -2926,8 +2926,8 @@
<xs:extension base="vol:CT_Function">
<xs:sequence>
<xs:element name="in" type="CT_Input" />
<xs:choice>
<xs:group ref="BasicNodeTypes" minOccurs="0" maxOccurs="2147483647" />
<xs:choice minOccurs="0" maxOccurs="2147483647">
<xs:group ref="BasicNodeTypes" />
</xs:choice>
<xs:element name="out" type="CT_Output" />
<xs:any namespace="##other" processContents="lax" />
Expand Down
Binary file modified presentations/3MF_Volumetric_2024_06_implicit.pptx
Binary file not shown.
1 change: 0 additions & 1 deletion volumetric.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ xmlns:xml="http://www.w3.org/XML/1998/namespace" targetNamespace="http://schemas
<xs:complexContent>
<xs:extension base="CT_Function">
<xs:attribute name="image3did" type="ST_ResourceID" use="required" />
<xs:attribute name="channel" type="ST_ChannelName" use="required" />
<xs:attribute name="filter" type="ST_Filter" default="linear" />
<xs:attribute name="valueoffset" type="ST_Number" default="0.0" />
<xs:attribute name="valuescale" type="ST_Number" default="1.0" />
Expand Down

0 comments on commit 6497051

Please sign in to comment.