1 """
2 Face of a triangle mesh.
3
4 """
5
6 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
7 from fabmetheus_utilities.vector3 import Vector3
8 from fabmetheus_utilities import euclidean
9
10 from fabmetheus_utilities import xml_simple_reader
11 from fabmetheus_utilities import xml_simple_writer
12 import cmath
13 import StringIO
14 import math
15
16
17 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
18 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
19 __date__ = '$Date: 2008/02/05 $'
20 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
21
22
24 'Add the faces.'
25 if geometryOutput.__class__ == list:
26 for element in geometryOutput:
27 addFaces(element, faces)
28 return
29 if geometryOutput.__class__ != dict:
30 return
31 for geometryOutputKey in geometryOutput.keys():
32 geometryOutputValue = geometryOutput[geometryOutputKey]
33 if geometryOutputKey == 'face':
34 for face in geometryOutputValue:
35 faces.append(face)
36 else:
37 addFaces(geometryOutputValue, faces)
38
47
49 "Get the vertex index that both edges have in common."
50 for edgeFirstVertexIndex in edgeFirst.vertexIndexes:
51 if edgeFirstVertexIndex == edgeSecond.vertexIndexes[0] or edgeFirstVertexIndex == edgeSecond.vertexIndexes[1]:
52 return edgeFirstVertexIndex
53 print( "Inconsistent GNU Triangulated Surface" )
54 print( edgeFirst )
55 print( edgeSecond )
56 return 0
57
59 'Get the faces.'
60 faces = []
61 addFaces(geometryOutput, faces)
62 return faces
63
71
72
74 "An edge of a triangle mesh."
76 "Set the face indexes to None."
77 self.faceIndexes = []
78 self.vertexIndexes = []
79 self.zMaximum = None
80 self.zMinimum = None
81
83 "Get the string representation of this Edge."
84 return str( self.index ) + ' ' + str( self.faceIndexes ) + ' ' + str(self.vertexIndexes)
85
87 "Add first None face index to input face index."
88 self.faceIndexes.append( faceIndex )
89
91 "Initialize from two vertex indices."
92 self.index = edgeIndex
93 self.vertexIndexes = vertexIndexes[:]
94 self.vertexIndexes.sort()
95 return self
96
97
99 "A face of a triangle mesh."
101 "Initialize."
102 self.edgeIndexes = []
103 self.index = None
104 self.vertexIndexes = []
105
107 "Get the string representation of this object info."
108 output = StringIO.StringIO()
109 self.addXML( 2, output )
110 return output.getvalue()
111
113 "Add to the attribute dictionary."
114 for vertexIndexIndex in xrange(len(self.vertexIndexes)):
115 vertexIndex = self.vertexIndexes[vertexIndexIndex]
116 attributeDictionary['vertex' + str(vertexIndexIndex)] = str(vertexIndex)
117
118 - def addXML(self, depth, output):
123
125 'Get the copy of this face.'
126 faceCopy = Face()
127 faceCopy.edgeIndexes = self.edgeIndexes[:]
128 faceCopy.index = self.index
129 faceCopy.vertexIndexes = self.vertexIndexes[:]
130 return faceCopy
131
133 "Initialize from edge indices."
134 if len(self.vertexIndexes) > 0:
135 return
136 self.index = faceIndex
137 self.edgeIndexes = edgeIndexes
138 for edgeIndex in edgeIndexes:
139 edges[ edgeIndex ].addFaceIndex( faceIndex )
140 for triangleIndex in xrange(3):
141 indexFirst = ( 3 - triangleIndex ) % 3
142 indexSecond = ( 4 - triangleIndex ) % 3
143 self.vertexIndexes.append( getCommonVertexIndex( edges[ edgeIndexes[ indexFirst ] ], edges[ edgeIndexes[ indexSecond ] ] ) )
144 return self
145
147 "Set the edge indexes to the vertex indexes."
148 if len(self.edgeIndexes) > 0:
149 return
150 for triangleIndex in xrange(3):
151 indexFirst = ( 3 - triangleIndex ) % 3
152 indexSecond = ( 4 - triangleIndex ) % 3
153 vertexIndexFirst = self.vertexIndexes[ indexFirst ]
154 vertexIndexSecond = self.vertexIndexes[ indexSecond ]
155 vertexIndexPair = [ vertexIndexFirst, vertexIndexSecond ]
156 vertexIndexPair.sort()
157 edgeIndex = len( edges )
158 if str( vertexIndexPair ) in edgeTable:
159 edgeIndex = edgeTable[ str( vertexIndexPair ) ]
160 else:
161 edgeTable[ str( vertexIndexPair ) ] = edgeIndex
162 edge = Edge().getFromVertexIndexes( edgeIndex, vertexIndexPair )
163 edges.append( edge )
164 edges[ edgeIndex ].addFaceIndex( self.index )
165 self.edgeIndexes.append( edgeIndex )
166