169 |
out.modifyBy(transformation) |
out.modifyBy(transformation) |
170 |
return out |
return out |
171 |
|
|
|
|
|
|
|
|
172 |
class Primitive(object): |
class Primitive(object): |
173 |
""" |
""" |
174 |
A general primitive |
A general primitive |
201 |
returns the underlying primitive |
returns the underlying primitive |
202 |
""" |
""" |
203 |
return self |
return self |
204 |
|
def hasSameOrientation(self,other): |
205 |
|
""" |
206 |
|
returns True if other is the same primitive and has the same orientation |
207 |
|
""" |
208 |
|
return self == other and isinstance(other,Primitive) |
209 |
|
|
210 |
def __neg__(self): |
def __neg__(self): |
211 |
""" |
""" |
274 |
""" |
""" |
275 |
return self.__primitive |
return self.__primitive |
276 |
|
|
277 |
|
def hasSameOrientation(self,other): |
278 |
|
""" |
279 |
|
returns True if other is the same primitive and has the same orientation |
280 |
|
""" |
281 |
|
return self == other and isinstance(other,ReversePrimitive) |
282 |
|
|
283 |
def __repr__(self): |
def __repr__(self): |
284 |
return "-%s(%s)"%(self.__primitive.__class__.__name__,self.getID()) |
return "-%s(%s)"%(self.__primitive.__class__.__name__,self.getID()) |
285 |
|
|
525 |
""" |
""" |
526 |
returns True curves are on the same position |
returns True curves are on the same position |
527 |
""" |
""" |
528 |
if isinstance(primitive.getUnderlyingPrimitive(),self.__class__): |
if hasattr(primitive,"getUnderlyingPrimitive"): |
529 |
if len(primitive) == len(self): |
if isinstance(primitive.getUnderlyingPrimitive(),self.__class__): |
530 |
|
if len(primitive) == len(self): |
531 |
cp0=self.getControlPoints() |
cp0=self.getControlPoints() |
532 |
cp1=primitive.getControlPoints() |
cp1=primitive.getControlPoints() |
533 |
match=True |
match=True |
540 |
if not cp0[i].isColocated(cp1[len(cp0)-1-i]): |
if not cp0[i].isColocated(cp1[len(cp0)-1-i]): |
541 |
return False |
return False |
542 |
return True |
return True |
543 |
else: |
return False |
|
return False |
|
|
else: |
|
|
return False |
|
544 |
|
|
545 |
class ReverseCurve(CurveBase, ReversePrimitive): |
class ReverseCurve(CurveBase, ReversePrimitive): |
546 |
""" |
""" |
714 |
""" |
""" |
715 |
returns True curves are on the same position |
returns True curves are on the same position |
716 |
""" |
""" |
717 |
if isinstance(primitive.getUnderlyingPrimitive(),Arc): |
if hasattr(primitive,"getUnderlyingPrimitive"): |
718 |
|
if isinstance(primitive.getUnderlyingPrimitive(),Arc): |
719 |
return (self.getCenterPoint().isColocated(primitive.getCenterPoint())) and ( \ |
return (self.getCenterPoint().isColocated(primitive.getCenterPoint())) and ( \ |
720 |
(self.getEndPoint().isColocated(primitive.getEndPoint()) and self.getStartPoint().isColocated(primitive.getStartPoint()) ) \ |
(self.getEndPoint().isColocated(primitive.getEndPoint()) and self.getStartPoint().isColocated(primitive.getStartPoint()) ) \ |
721 |
or (self.getEndPoint().isColocated(primitive.getStartPoint()) and self.getStartPoint().isColocated(primitive.getEndPoint()) ) ) |
or (self.getEndPoint().isColocated(primitive.getStartPoint()) and self.getStartPoint().isColocated(primitive.getEndPoint()) ) ) |
722 |
else: |
return False |
|
return False |
|
723 |
|
|
724 |
class ReverseArc(ArcBase, ReversePrimitive): |
class ReverseArc(ArcBase, ReversePrimitive): |
725 |
""" |
""" |
754 |
|
|
755 |
class CurveLoop(Primitive, PrimitiveBase): |
class CurveLoop(Primitive, PrimitiveBase): |
756 |
""" |
""" |
757 |
An oriented loop of 1D primitives (= curves and arcs) |
An oriented loop of one-dimensional manifolds (= curves and arcs) |
758 |
|
|
759 |
The loop must be closed and the L{Manifold1D}s should be oriented consistently. |
The loop must be closed and the L{Manifold1D}s should be oriented consistently. |
760 |
""" |
""" |
762 |
""" |
""" |
763 |
creates a polygon from a list of line curves. The curves must form a closed loop. |
creates a polygon from a list of line curves. The curves must form a closed loop. |
764 |
""" |
""" |
|
Primitive.__init__(self) |
|
|
PrimitiveBase.__init__(self) |
|
765 |
if len(curves)<2: |
if len(curves)<2: |
766 |
raise TypeError("at least two curves have to be given.") |
raise TypeError("at least two curves have to be given.") |
767 |
for i in range(len(curves)): |
for i in range(len(curves)): |
784 |
raise ValueError("loop is not closed.") |
raise ValueError("loop is not closed.") |
785 |
if not self.__curves[0].getStartPoint() == self.__curves[-1].getEndPoint(): |
if not self.__curves[0].getStartPoint() == self.__curves[-1].getEndPoint(): |
786 |
raise ValueError("loop is not closed.") |
raise ValueError("loop is not closed.") |
787 |
|
Primitive.__init__(self) |
788 |
|
PrimitiveBase.__init__(self) |
789 |
|
|
790 |
def getCurves(self): |
def getCurves(self): |
791 |
""" |
""" |
830 |
""" |
""" |
831 |
returns True if each curve is collocted with a curve in primitive |
returns True if each curve is collocted with a curve in primitive |
832 |
""" |
""" |
833 |
if isinstance(primitive,CurveLoop): |
if hasattr(primitive,"getUnderlyingPrimitive"): |
834 |
if len(primitive) == len(self): |
if isinstance(primitive.getUnderlyingPrimitive(),CurveLoop): |
835 |
cp0=self.getCurves() |
if len(primitive) == len(self): |
836 |
cp1=primitive.getCurves() |
cp0=self.getCurves() |
837 |
for c0 in cp0: |
cp1=primitive.getCurves() |
838 |
collocated = False |
for c0 in cp0: |
839 |
for c1 in cp1: |
collocated = False |
840 |
collocated = collocated or c0.isColocated(c1) |
for c1 in cp1: |
841 |
if not collocated: return False |
collocated = collocated or c0.isColocated(c1) |
842 |
return True |
if not collocated: return False |
843 |
else: |
return True |
844 |
return False |
return False |
|
else: |
|
|
return False |
|
845 |
|
|
846 |
def getGmshCommand(self,scaling_factor=1.): |
def getGmshCommand(self,scaling_factor=1.): |
847 |
""" |
""" |
857 |
|
|
858 |
class ReverseCurveLoop(ReversePrimitive, PrimitiveBase): |
class ReverseCurveLoop(ReversePrimitive, PrimitiveBase): |
859 |
""" |
""" |
860 |
An oriented loop of 1D primitives (= curves and arcs) |
An oriented loop of one-dimensional manifolds (= curves and arcs) |
861 |
|
|
862 |
The loop must be closed and the L{Manifold1D}s should be oriented consistently. |
The loop must be closed and the one-dimensional manifolds should be oriented consistently. |
863 |
""" |
""" |
864 |
def __init__(self,curve_loop): |
def __init__(self,curve_loop): |
865 |
""" |
""" |
879 |
def __len__(self): |
def __len__(self): |
880 |
return len(self.getUnderlyingPrimitive()) |
return len(self.getUnderlyingPrimitive()) |
881 |
|
|
882 |
class PrimitiveBase2D(PrimitiveBase): |
#= |
883 |
|
class Manifold2D(PrimitiveBase): |
884 |
""" |
""" |
885 |
general two-dimensional primitive |
general two-dimensional manifold |
886 |
""" |
""" |
887 |
def __init__(self): |
def __init__(self): |
|
""" |
|
|
create a two-dimensional primitive |
|
|
""" |
|
|
super(PrimitiveBase2D, self).__init__() |
|
|
|
|
|
def getBoundary(self): |
|
|
""" |
|
|
returns a list of the 1D primitives forming the boundary of the Surface (including holes) |
|
|
""" |
|
|
out=[] |
|
|
for i in self.getPrimitives(): |
|
|
if isinstance(i, Manifold1D): out.append(i) |
|
|
return out |
|
|
|
|
|
def getBoundary(self): |
|
|
""" |
|
|
returns a list of the 1D primitives forming the boundary of the Surface (including holes) |
|
|
""" |
|
|
out=[] |
|
|
for i in self.getPrimitives(): |
|
|
if isinstance(i, Manifold1D): out.append(i) |
|
|
return out |
|
|
|
|
|
def getBoundaryLoop(self): |
|
|
""" |
|
|
returns the loop defining the outer boundary |
|
|
""" |
|
|
raise NotImplementedError("getBoundaryLoop is not implemented for this class %s."%self.__class__.__name__) |
|
|
|
|
|
def getHoles(self): |
|
888 |
""" |
""" |
889 |
returns the holes |
create a two-dimensional manifold |
890 |
""" |
""" |
891 |
raise NotImplementedError("getHoles is not implemented for this class %s."%self.__class__.__name__) |
PrimitiveBase.__init__(self) |
892 |
|
|
893 |
def collectPrimitiveBases(self): |
def getBoundary(self): |
894 |
""" |
""" |
895 |
returns primitives used to construct the Surface |
returns a list of the one-dimensional manifolds forming the boundary of the Surface (including holes) |
896 |
""" |
""" |
897 |
out=[self] + self.getBoundaryLoop().collectPrimitiveBases() |
raise NotImplementedError() |
|
for i in self.getHoles(): out+=i.collectPrimitiveBases() |
|
|
return out |
|
898 |
|
|
899 |
class RuledSurface(PrimitiveBase2D): |
class RuledSurface(Primitive, Manifold2D): |
900 |
""" |
""" |
901 |
A ruled surface, i.e., a surface that can be interpolated using transfinite interpolation |
A ruled surface, i.e., a surface that can be interpolated using transfinite interpolation |
902 |
""" |
""" |
906 |
|
|
907 |
@param loop: L{CurveLoop} defining the boundary of the surface. |
@param loop: L{CurveLoop} defining the boundary of the surface. |
908 |
""" |
""" |
909 |
super(RuledSurface, self).__init__() |
if not isinstance(loop.getUnderlyingPrimitive(),CurveLoop): |
|
if not isinstance(loop,CurveLoop): |
|
910 |
raise TypeError("argument loop needs to be a CurveLoop object.") |
raise TypeError("argument loop needs to be a CurveLoop object.") |
911 |
if len(loop)<2: |
if len(loop)<2: |
912 |
raise TypeError("the loop must contain at least two Curves.") |
raise TypeError("the loop must contain at least two Curves.") |
913 |
if len(loop)>4: |
if len(loop)>4: |
914 |
raise TypeError("the loop must contain at least three Curves.") |
raise TypeError("the loop must contain at least three Curves.") |
915 |
|
Primitive.__init__(self) |
916 |
|
Manifold2D.__init__(self) |
917 |
self.__loop=loop |
self.__loop=loop |
918 |
|
|
919 |
|
def __neg__(self): |
920 |
|
""" |
921 |
|
returns a view onto the suface with reversed ordering |
922 |
|
""" |
923 |
|
return ReverseRuledSurface(self) |
924 |
|
|
925 |
def getBoundaryLoop(self): |
def getBoundaryLoop(self): |
926 |
""" |
""" |
927 |
returns the loop defining the outer boundary |
returns the loop defining the outer boundary |
928 |
""" |
""" |
929 |
return self.__loop |
return self.__loop |
930 |
|
|
931 |
def getHoles(self): |
def getBoundary(self): |
932 |
""" |
""" |
933 |
returns the holes |
returns a list of the one-dimensional manifolds forming the boundary of the Surface (including holes) |
934 |
""" |
""" |
935 |
return [] |
return self.getBoundaryLoop().getCurves() |
936 |
|
|
937 |
def getGmshCommand(self,scaling_factor=1.): |
def getGmshCommand(self,scaling_factor=1.): |
938 |
""" |
""" |
954 |
""" |
""" |
955 |
returns True if each curve is collocted with a curve in primitive |
returns True if each curve is collocted with a curve in primitive |
956 |
""" |
""" |
957 |
if isinstance(primitive,RuledSurface): |
if hasattr(primitive,"getUnderlyingPrimitive"): |
958 |
return self.getBoundaryLoop().isColocated(primitive.getBoundaryLoop()) |
if isinstance(primitive.getUnderlyingPrimitive(),RuledSurface): |
959 |
else: |
return self.getBoundaryLoop().isColocated(primitive.getBoundaryLoop()) |
960 |
return False |
return False |
961 |
|
|
962 |
|
def collectPrimitiveBases(self): |
963 |
|
""" |
964 |
|
returns primitives used to construct the Surface |
965 |
|
""" |
966 |
|
return [self] + self.getBoundaryLoop().collectPrimitiveBases() |
967 |
|
|
968 |
def createRuledSurface(*curves): |
def createRuledSurface(*curves): |
969 |
""" |
""" |
971 |
""" |
""" |
972 |
return RuledSurface(CurveLoop(*curves)) |
return RuledSurface(CurveLoop(*curves)) |
973 |
|
|
974 |
class PlaneSurface(PrimitiveBase2D): |
|
975 |
|
class ReverseRuledSurface(ReversePrimitive, Manifold2D): |
976 |
|
""" |
977 |
|
creates a view onto a L{RuledSurface} but with the reverse orientation |
978 |
|
""" |
979 |
|
def __init__(self,surface): |
980 |
|
""" |
981 |
|
creates a polygon from a list of line curves. The curves must form a closed loop. |
982 |
|
""" |
983 |
|
if not isinstance(surface, RuledSurface): |
984 |
|
raise ValueError("arguments need to be an instance of CurveLoop.") |
985 |
|
ReversePrimitive.__init__(self, surface) |
986 |
|
Manifold2D.__init__(self) |
987 |
|
|
988 |
|
def getBoundaryLoop(self): |
989 |
|
""" |
990 |
|
returns the CurveLoop defining the RuledSurface |
991 |
|
""" |
992 |
|
return -self.getUnderlyingPrimitive().getBoundaryLoop() |
993 |
|
|
994 |
|
def getBoundary(self): |
995 |
|
""" |
996 |
|
returns a list of the one-dimensional manifolds forming the boundary of the Surface (including holes) |
997 |
|
""" |
998 |
|
return self.getBoundaryLoop().getCurves() |
999 |
|
#============================== |
1000 |
|
class PlaneSurface(Primitive, Manifold2D): |
1001 |
""" |
""" |
1002 |
a plane surface with holes |
a plane surface with holes |
1003 |
""" |
""" |
1010 |
@note: A CurveLoop defining a hole should not have any lines in common with the exterior CurveLoop. |
@note: A CurveLoop defining a hole should not have any lines in common with the exterior CurveLoop. |
1011 |
A CurveLoop defining a hole should not have any lines in common with another CurveLoop defining a hole in the same surface. |
A CurveLoop defining a hole should not have any lines in common with another CurveLoop defining a hole in the same surface. |
1012 |
""" |
""" |
1013 |
super(PlaneSurface, self).__init__() |
if not isinstance(loop.getUnderlyingPrimitive(),CurveLoop): |
|
if not isinstance(loop,CurveLoop): |
|
1014 |
raise TypeError("argument loop needs to be a CurveLoop object.") |
raise TypeError("argument loop needs to be a CurveLoop object.") |
1015 |
for l in loop.getCurves(): |
for l in loop.getCurves(): |
1016 |
if not isinstance(l,Line): |
if not isinstance(l.getUnderlyingPrimitive(),Line): |
1017 |
raise TypeError("loop may be formed by Lines only.") |
raise TypeError("loop may be formed by Lines only.") |
1018 |
for i in range(len(holes)): |
for i in range(len(holes)): |
1019 |
if not isinstance(holes[i], CurveLoop): |
if not isinstance(holes[i].getUnderlyingPrimitive(), CurveLoop): |
1020 |
raise TypeError("%i-th hole needs to be a CurveLoop object.") |
raise TypeError("%i-th hole needs to be a CurveLoop object.") |
1021 |
for l in holes[i].getCurves(): |
for l in holes[i].getCurves(): |
1022 |
if not isinstance(l,Line): |
if not isinstance(l.getUnderlyingPrimitive(),Line): |
1023 |
raise TypeError("holes may be formed by Lines only.") |
raise TypeError("holes may be formed by Lines only.") |
1024 |
#TODO: check if lines and holes are in a plane |
#TODO: check if lines and holes are in a plane |
1025 |
#TODO: are holes really holes? |
#TODO: are holes really holes? |
1026 |
|
Primitive.__init__(self) |
1027 |
|
Manifold2D.__init__(self) |
1028 |
self.__loop=loop |
self.__loop=loop |
1029 |
self.__holes=holes |
self.__holes=holes |
1030 |
def getHoles(self): |
def getHoles(self): |
1032 |
returns the holes |
returns the holes |
1033 |
""" |
""" |
1034 |
return self.__holes |
return self.__holes |
1035 |
|
|
1036 |
def getBoundaryLoop(self): |
def getBoundaryLoop(self): |
1037 |
""" |
""" |
1038 |
returns the loop defining the boundary |
returns the loop defining the boundary |
1068 |
""" |
""" |
1069 |
returns True if each curve is collocted with a curve in primitive |
returns True if each curve is collocted with a curve in primitive |
1070 |
""" |
""" |
1071 |
if isinstance(primitive,PlaneSurface): |
if hasattr(primitive,"getUnderlyingPrimitive"): |
1072 |
if self.getBoundaryLoop().isColocated(primitive.getBoundaryLoop()): |
if isinstance(primitive.getUnderlyingPrimitive(),PlaneSurface): |
1073 |
hs0=self.getHoles() |
if self.getBoundaryLoop().isColocated(primitive.getBoundaryLoop()): |
1074 |
hs1=primitive.getHoles() |
hs0=self.getHoles() |
1075 |
if len(hs0) == len(hs1): |
hs1=primitive.getHoles() |
1076 |
for h0 in hs0: |
if len(hs0) == len(hs1): |
1077 |
collocated = False |
for h0 in hs0: |
1078 |
for h1 in hs1: |
collocated = False |
1079 |
collocated = collocated or h0.isColocated(h1) |
for h1 in hs1: |
1080 |
if not collocated: return False |
collocated = collocated or h0.isColocated(h1) |
1081 |
return True |
if not collocated: return False |
1082 |
return False |
return True |
1083 |
else: |
return False |
1084 |
return False |
def collectPrimitiveBases(self): |
1085 |
else: |
""" |
1086 |
return False |
returns primitives used to construct the Surface |
1087 |
|
""" |
1088 |
|
out=[self] + self.getBoundaryLoop().collectPrimitiveBases() |
1089 |
|
for i in self.getHoles(): out+=i.collectPrimitiveBases() |
1090 |
|
return out |
1091 |
|
def __neg__(self): |
1092 |
|
""" |
1093 |
|
returns a view onto the curve with reversed ordering |
1094 |
|
""" |
1095 |
|
return ReversePlaneSurface(self) |
1096 |
|
def getBoundary(self): |
1097 |
|
""" |
1098 |
|
returns a list of the one-dimensional manifolds forming the boundary of the Surface (including holes) |
1099 |
|
""" |
1100 |
|
out = []+ self.getBoundaryLoop().getCurves() |
1101 |
|
for h in self.getHoles(): out+=h.getCurves() |
1102 |
|
return out |
1103 |
|
|
1104 |
|
class ReversePlaneSurface(ReversePrimitive, Manifold2D): |
1105 |
|
""" |
1106 |
|
creates a view onto a L{PlaneSurface} but with the reverse orientation |
1107 |
|
""" |
1108 |
|
def __init__(self,surface): |
1109 |
|
""" |
1110 |
|
creates a polygon from a list of line curves. The curves must form a closed loop. |
1111 |
|
""" |
1112 |
|
if not isinstance(surface, PlaneSurface): |
1113 |
|
raise ValueError("arguments need to be an instance of PlaneSurface.") |
1114 |
|
ReversePrimitive.__init__(self, surface) |
1115 |
|
Manifold2D.__init__(self) |
1116 |
|
|
1117 |
|
def getBoundaryLoop(self): |
1118 |
|
""" |
1119 |
|
returns the CurveLoop defining the RuledSurface |
1120 |
|
""" |
1121 |
|
return -self.getUnderlyingPrimitive().getBoundaryLoop() |
1122 |
|
|
1123 |
|
def getHoles(self): |
1124 |
|
""" |
1125 |
|
returns a list of the one-dimensional manifolds forming the boundary of the Surface (including holes) |
1126 |
|
""" |
1127 |
|
return [ -h for h in self.getUnderlyingPrimitive().getHoles() ] |
1128 |
|
|
1129 |
|
def getBoundary(self): |
1130 |
|
""" |
1131 |
|
returns a list of the one-dimensional manifolds forming the boundary of the Surface (including holes) |
1132 |
|
""" |
1133 |
|
out = [] + self.getBoundaryLoop().getCurves() |
1134 |
|
for h in self.getHoles(): out+=h.getCurves() |
1135 |
|
return out |
1136 |
|
|
1137 |
|
|
1138 |
class SurfaceLoop(PrimitiveBase): |
#========================================================================= |
1139 |
|
class SurfaceLoop(Primitive, PrimitiveBase): |
1140 |
""" |
""" |
1141 |
a loop of 2D primitives. It defines the shell of a volume. |
a loop of 2D primitives. It defines the shell of a volume. |
1142 |
|
|
1146 |
""" |
""" |
1147 |
creates a surface loop |
creates a surface loop |
1148 |
""" |
""" |
|
super(SurfaceLoop, self).__init__() |
|
1149 |
if len(surfaces)<2: |
if len(surfaces)<2: |
1150 |
raise TypeError("at least two surfaces have to be given.") |
raise TypeError("at least two surfaces have to be given.") |
1151 |
for i in range(len(surfaces)): |
for i in range(len(surfaces)): |
1152 |
if not isinstance(surfaces[i],PrimitiveBase2D): |
if not isinstance(surfaces[i].getUnderlyingPrimitive(),Manifold2D): |
1153 |
raise TypeError("%s-th argument is not a PrimitiveBase2D object."%i) |
raise TypeError("%s-th argument is not a Manifold2D object."%i) |
1154 |
|
Primitive.__init__(self) |
1155 |
|
PrimitiveBase.__init__(self) |
1156 |
# for the curves a loop: |
# for the curves a loop: |
1157 |
used=[ True for s in surfaces] |
used=[ False for s in surfaces] |
1158 |
self.__surfaces=[surfaces[0]] |
self.__surfaces=[surfaces[0]] |
1159 |
edges=[ e in surfaces[0].getBoundary() ] |
used[0]= True |
1160 |
used_edges=[ False in surfaces[0].getBoundary() ] |
edges=[ e for e in surfaces[0].getBoundary() ] |
1161 |
while min(used): |
used_edges=[ False for e in surfaces[0].getBoundary() ] |
1162 |
|
while not min(used): |
1163 |
found=False |
found=False |
1164 |
for i in xrange(len(surfaces)): |
for i in xrange(len(surfaces)): |
1165 |
if not used[i]: |
if not used[i]: |
1166 |
i_boundary=surfaces[i].getBoundary() |
i_boundary=surfaces[i].getBoundary() |
1167 |
for ib in xrange(i_boundary): |
print i, i_boundary |
1168 |
|
for ib in xrange(len(i_boundary)): |
1169 |
|
print ib, i_boundary[ib], edges |
1170 |
if i_boundary[ib] in edges: |
if i_boundary[ib] in edges: |
1171 |
if used_edges[edges.index(i_boundary[ib])]: |
if used_edges[edges.index(i_boundary[ib])]: |
1172 |
raise TypeError("boundary segment %s is shared by more than one surface."%str(i_boundary[ib])) |
raise ValueError("boundary segment %s is shared by more than one surface."%str(i_boundary[ib])) |
1173 |
used_edges[edges.index(i_boundary[ib])]=True |
used_edges[edges.index(i_boundary[ib])]=True |
1174 |
self.__surfaces.append(surfaces[i]) |
self.__surfaces.append(surfaces[i]) |
1175 |
for b in i_boundary: |
for b in i_boundary: |
1182 |
if found: break |
if found: break |
1183 |
if not found: |
if not found: |
1184 |
raise ValueError("loop is not closed.") |
raise ValueError("loop is not closed.") |
1185 |
|
print min(used_edges), used_edges |
1186 |
if min(used_edges): |
if min(used_edges): |
1187 |
raise ValueError("loop is not closed. Surface is missing.") |
raise ValueError("loop is not closed. Surface is missing.") |
1188 |
def __len__(self): |
def __len__(self): |
1191 |
""" |
""" |
1192 |
return len(self.__surfaces) |
return len(self.__surfaces) |
1193 |
|
|
1194 |
|
def __neg__(self): |
1195 |
|
""" |
1196 |
|
returns a view onto the curve with reversed ordering |
1197 |
|
""" |
1198 |
|
return ReverseSurfaceLoop(self) |
1199 |
|
|
1200 |
def getSurfaces(self): |
def getSurfaces(self): |
1201 |
""" |
""" |
1202 |
returns the surfaces defining the SurfaceLoop |
returns the surfaces defining the SurfaceLoop |
1203 |
""" |
""" |
1204 |
return self.__curves |
return self.__surfaces |
1205 |
|
|
1206 |
def collectPrimitiveBases(self): |
def collectPrimitiveBases(self): |
1207 |
""" |
""" |
1210 |
out=[self] |
out=[self] |
1211 |
for c in self.getSurfaces(): out+=c.collectPrimitiveBases() |
for c in self.getSurfaces(): out+=c.collectPrimitiveBases() |
1212 |
return out |
return out |
1213 |
|
|
1214 |
def getGmshCommand(self,scaling_factor=1.): |
def getGmshCommand(self,scaling_factor=1.): |
1215 |
""" |
""" |
1216 |
returns the Gmsh command(s) to create the primitive |
returns the Gmsh command(s) to create the primitive |
1238 |
""" |
""" |
1239 |
returns True if each surface is collocted with a curve in primitive and vice versa. |
returns True if each surface is collocted with a curve in primitive and vice versa. |
1240 |
""" |
""" |
1241 |
if isinstance(primitive,SurfaceLoop): |
if hasattr(primitive,"getUnderlyingPrimitive"): |
1242 |
if len(primitive) == len(self): |
if isinstance(primitive.getUnderlyingPrimitive(),SurfaceLoop): |
1243 |
sp0=self.getSurfaces() |
if len(primitive) == len(self): |
1244 |
sp1=primitive.getCurves() |
sp0=self.getSurfaces() |
1245 |
for s0 in sp0: |
sp1=primitive.getCurves() |
1246 |
collocated = False |
for s0 in sp0: |
1247 |
for s1 in sp1: |
collocated = False |
1248 |
collocated = collocated or s0.isColocated(s1) |
for s1 in sp1: |
1249 |
if not collocated: return False |
collocated = collocated or s0.isColocated(s1) |
1250 |
return True |
if not collocated: return False |
1251 |
else: |
return True |
1252 |
return False |
return False |
1253 |
else: |
|
1254 |
return False |
class ReverseSurfaceLoop(ReversePrimitive, PrimitiveBase): |
1255 |
|
""" |
1256 |
|
a view to SurfaceLoop with reverse orientaion |
1257 |
|
|
1258 |
|
The loop must represent a closed shell, and the primitives should be oriented consistently. |
1259 |
|
An oriented loop of 2-dimensional manifolds (= RuledSurface, PlaneSurface) |
1260 |
|
|
1261 |
|
The loop must be closed and the one-dimensional manifolds should be oriented consistently. |
1262 |
|
""" |
1263 |
|
def __init__(self,surface_loop): |
1264 |
|
""" |
1265 |
|
creates a polygon from a list of line surfaces. The curves must form a closed loop. |
1266 |
|
""" |
1267 |
|
if not isinstance(surface_loop, SurfaceLoop): |
1268 |
|
raise ValueError("arguments need to be an instance of SurfaceLoop.") |
1269 |
|
ReversePrimitive.__init__(self, surface_loop) |
1270 |
|
PrimitiveBase.__init__(self) |
1271 |
|
|
1272 |
|
def getSurfaces(self): |
1273 |
|
""" |
1274 |
|
returns the surfaces defining the SurfaceLoop |
1275 |
|
""" |
1276 |
|
return [ -s for s in self.getUnderlyingPrimitive().getSurfaces() ] |
1277 |
|
|
1278 |
|
def __len__(self): |
1279 |
|
return len(self.getUnderlyingPrimitive()) |
1280 |
#========================== |
#========================== |
1281 |
class Volume(PrimitiveBase): |
class Volume(PrimitiveBase): |
1282 |
""" |
""" |