50 |
#include <TetrahedronByEdges.hpp> |
#include <TetrahedronByEdges.hpp> |
51 |
|
|
52 |
#include <set> |
#include <set> |
53 |
|
#include <iostream> |
54 |
|
|
55 |
class SurfaceMeshGenerator::Internals |
class SurfaceMeshGenerator::Internals |
56 |
{ |
{ |
65 |
return true; |
return true; |
66 |
if (s1[1]<s2[1]) |
if (s1[1]<s2[1]) |
67 |
return true; |
return true; |
68 |
if (s1[1]<s2[1]) |
if (s1[2]<s2[2]) |
69 |
return true; |
return true; |
70 |
return false; |
return false; |
71 |
} |
} |
87 |
//! list of cut edges and intersection vertex. |
//! list of cut edges and intersection vertex. |
88 |
std::map<Edge::Pair, size_t> edgesRef; |
std::map<Edge::Pair, size_t> edgesRef; |
89 |
|
|
90 |
EdgePairList triangleList; |
std::vector<ReferenceCounting<EdgePairList> > triangleListes; |
91 |
|
|
92 |
EdgePairList localTriangleList; |
EdgePairList localTriangleList; |
93 |
|
|
94 |
//! This list is used to provide an orientation to the Surfacic Elements. |
//! This list is used to provide an orientation to the Surfacic Elements. |
95 |
std::list<TinyVector<3> > InsideVertexList; |
std::list<TinyVector<3> > InsideVertexList; |
96 |
|
|
97 |
//! list of cut edges and intersection vertex. |
//! list of cut edges and intersection vertex. |
98 |
VerticesList verticesList; |
std::vector<ReferenceCounting<VerticesList> > verticesListes; |
99 |
|
|
100 |
HexaTetraAssociation hexaTetraAssociation; |
HexaTetraAssociation hexaTetraAssociation; |
101 |
|
|
106 |
const Shape& S); |
const Shape& S); |
107 |
|
|
108 |
void __createTriangles(const Shape& S, |
void __createTriangles(const Shape& S, |
109 |
const Reference::Representation& ref); |
const Reference::Representation& ref,const int objectNumber); |
110 |
|
|
111 |
void __setBoundaryType(const Boundary& B, |
void __setBoundaryType(const Boundary& B, |
112 |
POVRayReferences& vrRefList, |
POVRayReferences& vrRefList, |
188 |
|
|
189 |
void SurfaceMeshGenerator::Internals:: |
void SurfaceMeshGenerator::Internals:: |
190 |
__createTriangles(const Shape& S, |
__createTriangles(const Shape& S, |
191 |
const Reference::Representation& ref) |
const Reference::Representation& ref,const int objectNumber) |
192 |
{ |
{ |
193 |
for(SurfaceMeshGenerator::Internals::HexaTetraAssociation::iterator i |
for(SurfaceMeshGenerator::Internals::HexaTetraAssociation::iterator i |
194 |
= hexaTetraAssociation.begin(); |
= hexaTetraAssociation.begin(); |
234 |
|
|
235 |
//! Stores the Edges on which the vertex will be computed. |
//! Stores the Edges on which the vertex will be computed. |
236 |
for (size_t i=0; i<cutEdges.size(); ++i) |
for (size_t i=0; i<cutEdges.size(); ++i) |
237 |
verticesList[*cutEdges[i]] = new Vertex(Internals::__splitEdge(*cutEdges[i], ref, S)); |
(*verticesListes[objectNumber])[*cutEdges[i]] = new Vertex(Internals::__splitEdge(*cutEdges[i], ref, S)); |
238 |
break; |
break; |
239 |
} |
} |
240 |
case 4: { |
case 4: { |
276 |
} |
} |
277 |
|
|
278 |
for (size_t i=0; i<4; ++i) { |
for (size_t i=0; i<4; ++i) { |
279 |
verticesList[*cutEdges[i]] = new Vertex(__splitEdge(*cutEdges[i], ref, S)); |
(*verticesListes[objectNumber])[*cutEdges[i]] = new Vertex(__splitEdge(*cutEdges[i], ref, S)); |
280 |
} |
} |
281 |
|
|
282 |
//! Addes a triangle to the list. |
//! Addes a triangle to the list. |
309 |
|
|
310 |
for (EdgePairList::iterator t = localTriangleList.begin(); |
for (EdgePairList::iterator t = localTriangleList.begin(); |
311 |
t != localTriangleList.end(); ++t) { |
t != localTriangleList.end(); ++t) { |
312 |
triangleList.push_front(*t); |
(*triangleListes[objectNumber]).push_front(*t); |
313 |
} |
} |
314 |
|
|
315 |
localTriangleList.clear(); |
localTriangleList.clear(); |
534 |
void plot2(const SurfaceMeshOfTriangles& s, |
void plot2(const SurfaceMeshOfTriangles& s, |
535 |
std::set<const Cell*>& hlist, |
std::set<const Cell*>& hlist, |
536 |
Structured3DMesh& SMesh); |
Structured3DMesh& SMesh); |
537 |
|
void plotmedit(const SurfaceMeshOfTriangles& s_mesh,std::set<const Cell*>& toTreatHexahedra,size_t nobj); |
538 |
|
void Bary(Vertex& P,TinyVector<3>& P0,TinyVector<3>& V12,TinyVector<3>& V02); |
539 |
|
|
540 |
|
|
541 |
|
|
586 |
} |
} |
587 |
|
|
588 |
otherReferences.erase(O.reference()); |
otherReferences.erase(O.reference()); |
589 |
|
size_t nobject = scene.nbObjects(); |
590 |
|
std::cout<<"nb object "<<nobject<<"\n"; |
591 |
|
(*__internals).verticesListes.resize(nobject); |
592 |
|
(*__internals).triangleListes.resize(nobject); |
593 |
|
|
594 |
|
for(int no=0 ; no<nobject ; ++no) |
595 |
|
{ |
596 |
|
(*__internals).triangleListes[no]= new SurfaceMeshGenerator::Internals::EdgePairList; |
597 |
|
(*__internals).verticesListes[no]= new SurfaceMeshGenerator::Internals::VerticesList; |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
for (size_t i = 0; i<SMesh.nbEdges(); i++) { |
for (size_t i = 0; i<SMesh.nbEdges(); i++) { |
602 |
Edge& e = SMesh.edge(i); |
Edge& e = SMesh.edge(i); |
603 |
#warning THIS TEST IS NOT ENOUGH! THINK TO THE BORDER! |
#warning THIS TEST IS NOT ENOUGH! THINK TO THE BORDER! |
604 |
if((e(0).Ref().insideDomain() xor e(1).Ref().insideDomain()) |
if((e(0).Ref().insideDomain() xor e(1).Ref().insideDomain()) |
605 |
and ((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref)))) |
and ((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref)))) |
606 |
{ |
{ |
607 |
(*__internals).verticesList[e] = new Vertex((*__internals).__splitEdge(e, ref, S)); |
(*(*__internals).verticesListes[0])[e] = new Vertex((*__internals).__splitEdge(e, ref, S)); |
608 |
(*__internals).edgesRef[e] = 1; |
(*__internals).edgesRef[e] = 1; |
609 |
} |
} |
610 |
} |
} |
615 |
/// a triangulation has been generated inside the hexahedron |
/// a triangulation has been generated inside the hexahedron |
616 |
std::set<const Cell*> meshedHexahedra; |
std::set<const Cell*> meshedHexahedra; |
617 |
|
|
618 |
if ((*__internals).verticesList.size()==0) { |
if ((*(*__internals).verticesListes[0]).size()==0) { |
619 |
fferr(2) << __FILE__ << ':' << __LINE__ << ": " |
fferr(2) << __FILE__ << ':' << __LINE__ << ": " |
620 |
<< "meshing object " << S << " a problem occured ...\n" |
<< "meshing object " << S << " a problem occured ...\n" |
621 |
<< "Check that:\n" |
<< "Check that:\n" |
658 |
|
|
659 |
for (size_t l=0; l<H.numberOfEdges(); l++) { |
for (size_t l=0; l<H.numberOfEdges(); l++) { |
660 |
Edge& e = H.edge(l); |
Edge& e = H.edge(l); |
661 |
if ((*__internals).verticesList.count(e) > 0) { |
if ((*(*__internals).verticesListes[0]).count(e) > 0) { |
662 |
intersected = true; |
intersected = true; |
663 |
cuttedHexahedra.insert(¤tCell); |
cuttedHexahedra.insert(¤tCell); |
664 |
break; |
break; |
827 |
|
|
828 |
//! Stores the Edges on which the vertex will be computed. |
//! Stores the Edges on which the vertex will be computed. |
829 |
for (size_t i=0; i<cutEdges.size(); ++i) { |
for (size_t i=0; i<cutEdges.size(); ++i) { |
830 |
(*__internals).verticesList[*cutEdges[i]] |
(*(*__internals).verticesListes[0])[*cutEdges[i]] |
831 |
= new Vertex((*__internals).__splitEdge(*cutEdges[i], ref, S)); |
= new Vertex((*__internals).__splitEdge(*cutEdges[i], ref, S)); |
832 |
(*__internals).edgesRef[*cutEdges[i]] = 1; |
(*__internals).edgesRef[*cutEdges[i]] = 1; |
833 |
} |
} |
873 |
} |
} |
874 |
|
|
875 |
for (size_t i=0; i<4; ++i) { |
for (size_t i=0; i<4; ++i) { |
876 |
(*__internals).verticesList[*cutEdges[i]] |
(*(*__internals).verticesListes[0])[*cutEdges[i]] |
877 |
= new Vertex((*__internals).__splitEdge(*cutEdges[i], ref, S)); |
= new Vertex((*__internals).__splitEdge(*cutEdges[i], ref, S)); |
878 |
(*__internals).edgesRef[*cutEdges[i]] = 1; |
(*__internals).edgesRef[*cutEdges[i]] = 1; |
879 |
} |
} |
911 |
for (SurfaceMeshGenerator::Internals::EdgePairList::iterator t |
for (SurfaceMeshGenerator::Internals::EdgePairList::iterator t |
912 |
= (*__internals).localTriangleList.begin(); |
= (*__internals).localTriangleList.begin(); |
913 |
t != (*__internals).localTriangleList.end(); ++t) { |
t != (*__internals).localTriangleList.end(); ++t) { |
914 |
(*__internals).triangleList.push_front(*t); |
(*(*__internals).triangleListes[0]).push_front(*t); |
915 |
} |
} |
916 |
} else { |
} else { |
917 |
(*__internals).hexaTetraAssociation[¤tCell] |
(*__internals).hexaTetraAssociation[¤tCell] |
924 |
} |
} |
925 |
} |
} |
926 |
|
|
927 |
// (*__internals).triangleList.clear(); |
// (*(*__internals).triangleListes[0]).clear(); |
928 |
// (*__internals).verticesList.clear(); |
// (*(*__internals).verticesListes[0]).clear(); |
929 |
|
|
930 |
|
|
931 |
// (*__internals).__createTriangles(S, ref); |
// (*__internals).__createTriangles(S, ref,0); |
932 |
|
|
933 |
|
// size_t nobj= (*(*__internals).triangleListes[0]).size(); |
934 |
|
//std::cout<<"nb tr objet1 "<<nobj<<" \n"; |
935 |
|
|
936 |
|
// size_t num=0; |
937 |
// for(ObjectReferences::iterator i = otherReferences.begin(); |
// for(ObjectReferences::iterator i = otherReferences.begin(); |
938 |
// i != otherReferences.end(); ++i) { |
// i != otherReferences.end(); ++i) { |
939 |
|
// num+=1; |
940 |
// for(size_t n = 0; n<scene.nbObjects(); ++n) { |
// for(size_t n = 0; n<scene.nbObjects(); ++n) { |
941 |
// Reference::Representation otherRef; |
// Reference::Representation otherRef; |
942 |
// otherRef.resize(scene.nbObjects()); |
// otherRef.resize(scene.nbObjects()); |
943 |
|
// |
944 |
|
// if (scene.object(n).reference() == ((*i).first)) { |
945 |
|
// otherRef[n] = true; |
946 |
|
// (*__internals).__createTriangles(*(scene.object(n).shape()), |
947 |
|
// otherRef,num); |
948 |
|
// } |
949 |
|
// } |
950 |
|
// } |
951 |
|
|
952 |
|
// std::cout<<"nb tr objet2 "<<(*(*__internals).verticesListes[1]).size()<<" \n"; |
953 |
|
// size_t nobjother=(*(*__internals).triangleListes[1]).size(); |
954 |
|
|
955 |
|
size_t ntr=0; |
956 |
|
for(size_t n = 0; n<scene.nbObjects(); ++n) |
957 |
|
ntr+=(*(*__internals).verticesListes[n]).size(); |
958 |
|
|
959 |
// if (scene.object(n).reference() == ((*i).first)) { |
s_mesh.setNumberOfVertices(ntr); |
|
// otherRef[n] = true; |
|
|
// (*__internals).__createTriangles(*(scene.object(n).shape()), |
|
|
// otherRef); |
|
|
// } |
|
|
// } |
|
|
// } |
|
|
|
|
|
s_mesh.setNumberOfVertices((*__internals).verticesList.size()); |
|
960 |
|
|
961 |
//! copies vertices into the s_mesh. |
//! copies vertices into the s_mesh. |
962 |
int i = 0; |
int i = 0; |
963 |
for(SurfaceMeshGenerator::Internals::VerticesList::iterator splitVertex |
for(size_t n = 0; n<scene.nbObjects(); ++n) |
964 |
= (*__internals).verticesList.begin(); |
{ |
965 |
splitVertex != (*__internals).verticesList.end(); ++splitVertex) { |
for(SurfaceMeshGenerator::Internals::VerticesList::iterator splitVertex |
966 |
|
= (*(*__internals).verticesListes[n]).begin(); |
967 |
s_mesh.vertex(i) = (*(*splitVertex).second); |
splitVertex != (*(*__internals).verticesListes[n]).end(); ++splitVertex) |
968 |
delete (*splitVertex).second; |
{ |
969 |
(*splitVertex).second = &s_mesh.vertex(i); |
s_mesh.vertex(i) = (*(*splitVertex).second); |
970 |
i++; |
delete (*splitVertex).second; |
971 |
|
(*splitVertex).second = &s_mesh.vertex(i); |
972 |
|
i++; |
973 |
|
} |
974 |
} |
} |
975 |
|
|
976 |
// std::set<const Cell*> toTreatHexahedra; |
|
977 |
// std::set_difference (cuttedHexahedra.begin(), cuttedHexahedra.end(), |
//std::set<const Cell*> toTreatHexahedra; |
978 |
// meshedHexahedra.begin(), meshedHexahedra.end(), |
//std::set_difference (cuttedHexahedra.begin(), cuttedHexahedra.end(), |
979 |
// inserter(toTreatHexahedra, toTreatHexahedra.begin())); |
// meshedHexahedra.begin(), meshedHexahedra.end(), |
980 |
|
// inserter(toTreatHexahedra, toTreatHexahedra.begin())); |
981 |
|
//******************************************************************************* |
982 |
|
/* for(SurfaceMeshGenerator::Internals::EdgePairList::iterator currentTriangle |
983 |
|
= (*(*__internals).triangleListes[0]).begin(); |
984 |
|
currentTriangle != (*(*__internals).triangleListes[0]).end(); |
985 |
|
++currentTriangle) |
986 |
|
{ |
987 |
|
Vertex& V0 = *((*(*__internals).verticesListes[0])[(*currentTriangle)[0]]); |
988 |
|
Vertex& V1 = *((*(*__internals).verticesListes[0])[(*currentTriangle)[1]]); |
989 |
|
Vertex& V2 = *((*(*__internals).verticesListes[0])[(*currentTriangle)[2]]); |
990 |
|
|
991 |
|
//equation of the plan |
992 |
|
TinyVector<3> V01,V12,V02; |
993 |
|
V01=V1.Vector3()-V0.Vector3(); |
994 |
|
V12=V2.Vector3()-V1.Vector3(); |
995 |
|
V02=V2.Vector3()-V0.Vector3(); |
996 |
|
TinyVector<3> coeff; |
997 |
|
coeff=V01^V02; |
998 |
|
|
999 |
|
real_t d=-(coeff[0]*V0[0]+coeff[1]*V0[1]+coeff[2]*V0[2]); |
1000 |
|
std::cout<<"--------------------------------------------------------------\n"; |
1001 |
|
for(SurfaceMeshGenerator::Internals::EdgePairList::iterator currentTriangle |
1002 |
|
= (*(*__internals).triangleListes[1]).begin(); |
1003 |
|
currentTriangle != (*(*__internals).triangleListes[1]).end(); |
1004 |
|
++currentTriangle) |
1005 |
|
{ |
1006 |
|
// std::cout<<"*************************\n"; |
1007 |
|
Vertex& Vo0 = *((*(*__internals).verticesListes[1])[(*currentTriangle)[0]]); |
1008 |
|
Vertex& Vo1 = *((*(*__internals).verticesListes[1])[(*currentTriangle)[1]]); |
1009 |
|
Vertex& Vo2 = *((*(*__internals).verticesListes[1])[(*currentTriangle)[2]]); |
1010 |
|
|
1011 |
|
|
1012 |
|
real_t pscalar,k; |
1013 |
|
{ |
1014 |
|
Vertex P; |
1015 |
|
TinyVector<3> Vo01; |
1016 |
|
Vo01=Vo1.Vector3()-Vo0.Vector3(); |
1017 |
|
pscalar=coeff*Vo01; |
1018 |
|
if(pscalar>1e-8) |
1019 |
|
{ |
1020 |
|
k=-(coeff[0]*Vo0[0]+coeff[1]*Vo0[1]+coeff[2]*Vo0[2]+d)/pscalar; |
1021 |
|
P=Vo0+k*Vo01; |
1022 |
|
TinyVector<3> P0=P.Vector3()-V2.Vector3(); |
1023 |
|
//std::cout<<"verif "<<coeff[0]*P.Vector3()[0]+coeff[1]*P.Vector3()[1]+coeff[2]*P.Vector3()[2]+d<<"\n"; |
1024 |
|
Bary(P,P0,V12,V02); |
1025 |
|
} |
1026 |
|
} |
1027 |
|
{ |
1028 |
|
Vertex P; |
1029 |
|
TinyVector<3> Vo02; |
1030 |
|
Vo02=Vo2.Vector3()-Vo0.Vector3(); |
1031 |
|
pscalar=coeff*Vo02; |
1032 |
|
|
1033 |
|
if(pscalar>1e-8) |
1034 |
|
{ |
1035 |
|
k=-(coeff[0]*Vo0[0]+coeff[1]*Vo0[1]+coeff[2]*Vo0[2]+d)/pscalar; |
1036 |
|
P=Vo0+k*Vo02; |
1037 |
|
TinyVector<3> P0=P.Vector3()-V2.Vector3(); |
1038 |
|
Bary(P,P0,V12,V02); |
1039 |
|
} |
1040 |
|
} |
1041 |
|
{ |
1042 |
|
Vertex P; |
1043 |
|
TinyVector<3> Vo12; |
1044 |
|
Vo12=Vo2.Vector3()-Vo1.Vector3(); |
1045 |
|
pscalar=coeff*Vo12; |
1046 |
|
if(pscalar>1e-8) |
1047 |
|
{ |
1048 |
|
k=-(coeff[0]*Vo1[0]+coeff[1]*Vo1[1]+coeff[2]*Vo1[2]+d)/pscalar; |
1049 |
|
Vertex P; |
1050 |
|
P=Vo1+k*Vo12; |
1051 |
|
TinyVector<3> P0=P.Vector3()-V2.Vector3(); |
1052 |
|
Bary(P,P0,V12,V02); |
1053 |
|
} |
1054 |
|
} |
1055 |
|
} |
1056 |
|
}*/ |
1057 |
|
|
1058 |
i = 0; |
i = 0; |
1059 |
|
size_t ncell=0; |
1060 |
|
for(size_t n = 0; n<scene.nbObjects(); ++n) |
1061 |
|
ncell+=(*(*__internals).triangleListes[n]).size(); |
1062 |
|
|
1063 |
s_mesh.setNumberOfCells((*__internals).triangleList.size()); |
s_mesh.setNumberOfCells(ncell); |
1064 |
|
|
1065 |
SurfaceMeshGenerator::Internals::MotherCellList::iterator motherCell |
SurfaceMeshGenerator::Internals::MotherCellList::iterator motherCell |
1066 |
= (*__internals).cellList.begin(); |
= (*__internals).cellList.begin(); |
1067 |
|
|
1068 |
for(SurfaceMeshGenerator::Internals::EdgePairList::iterator currentTriangle |
for(size_t n = 0; n<scene.nbObjects(); ++n) |
1069 |
= (*__internals).triangleList.begin(); |
{ |
1070 |
currentTriangle != (*__internals).triangleList.end(); |
for(SurfaceMeshGenerator::Internals::EdgePairList::iterator currentTriangle |
1071 |
++currentTriangle) { |
= (*(*__internals).triangleListes[n]).begin(); |
1072 |
Vertex& V0 = *((*__internals).verticesList[(*currentTriangle)[0]]); |
currentTriangle != (*(*__internals).triangleListes[n]).end(); |
1073 |
Vertex& V1 = *((*__internals).verticesList[(*currentTriangle)[1]]); |
++currentTriangle) |
1074 |
Vertex& V2 = *((*__internals).verticesList[(*currentTriangle)[2]]); |
{ |
1075 |
|
Vertex& V0 = *((*(*__internals).verticesListes[n])[(*currentTriangle)[0]]); |
1076 |
|
Vertex& V1 = *((*(*__internals).verticesListes[n])[(*currentTriangle)[1]]); |
1077 |
|
Vertex& V2 = *((*(*__internals).verticesListes[n])[(*currentTriangle)[2]]); |
1078 |
|
|
1079 |
s_mesh.cell(i) = Triangle(V0,V1,V2); |
s_mesh.cell(i) = Triangle(V0,V1,V2); |
1080 |
#warning SHOULD USE BC NUMBER (ie OBJECT NUMBER IN SCENE INSTEAD) |
#warning SHOULD USE BC NUMBER (ie OBJECT NUMBER IN SCENE INSTEAD) |
1081 |
|
s_mesh.cell(i).reference() = 1; |
1082 |
s_mesh.cell(i).reference() = 1; |
s_mesh.cell(i).setMother(*motherCell); |
1083 |
s_mesh.cell(i).setMother(*motherCell); |
i++; |
1084 |
|
motherCell++; |
1085 |
i++; |
} |
|
motherCell++; |
|
1086 |
} |
} |
1087 |
|
|
1088 |
// plot2(s_mesh, toTreatHexahedra, SMesh); |
// plotmedit(s_mesh,toTreatHexahedra,nobj); |
1089 |
|
// plot2(s_mesh, toTreatHexahedra, SMesh); |
1090 |
} |
} |
1091 |
|
|
1092 |
|
|
1103 |
} |
} |
1104 |
|
|
1105 |
|
|
1106 |
// #include <vtkPolyDataMapper.h> |
void Bary(Vertex& P,TinyVector<3>& P0,TinyVector<3>& V12,TinyVector<3>& V02) |
1107 |
// #include <vtkRenderWindow.h> |
{ |
1108 |
// #include <vtkRenderWindowInteractor.h> |
TinyMatrix<2,2> mat; |
1109 |
// #include <vtkTriangle.h> |
real_t det=V02[0]*V12[1]-V02[1]*V12[0]; |
1110 |
// #include <vtkHexahedron.h> |
size_t compt=0; |
1111 |
// #include <vtkTetra.h> |
real_t eps=-1e-10; |
1112 |
// #include <vtkUnstructuredGrid.h> |
if(det!=0.) |
1113 |
// #include <vtkDataSetMapper.h> |
{ |
1114 |
// #include <vtkDataSetToPolyDataFilter.h> |
det=1./det; |
1115 |
// #include <vtkDoubleArray.h> |
mat(0,0)=-det*V12[1]; |
1116 |
|
mat(1,0)=det*V02[1]; |
1117 |
|
mat(1,1)=-det*V02[0]; |
1118 |
|
mat(0,1)=det*V12[0]; |
1119 |
// void plot2(const SurfaceMeshOfTriangles& s, |
TinyVector<2> bary,secondmb; |
1120 |
// std::set<const Cell*>& hlist, |
secondmb[0]=P0[0]; |
1121 |
// Structured3DMesh& m) |
secondmb[1]=P0[1]; |
1122 |
// { |
bary=mat*secondmb; |
1123 |
// vtkRenderer *ren1= vtkRenderer::New(); |
if(bary[0]>=eps && bary[1]>=eps && (1.-bary[0]-bary[1])>=eps) |
1124 |
|
compt+=1; |
1125 |
// vtkActor *anActor1 = vtkActor::New(); |
} |
1126 |
// vtkActor *anActor2 = vtkActor::New(); |
else |
1127 |
|
compt+=1; |
1128 |
// { |
{ |
1129 |
// vtkPoints* vertices = vtkPoints::New(); |
det=V02[1]*V12[2]-V02[2]*V12[1]; |
1130 |
|
if(det!=0.) |
1131 |
// vertices->SetNumberOfPoints(m.numberOfVertices()); |
{ |
1132 |
|
det=1./det; |
1133 |
// for (size_t i=0; i<m.numberOfVertices(); ++i) { |
mat(0,0)=-det*V12[2]; |
1134 |
// const Vertex& X = m.vertex(i); |
mat(1,0)=det*V02[2]; |
1135 |
// vertices->InsertPoint(i,X[0],X[1],X[2]); |
mat(1,1)=-det*V02[1]; |
1136 |
// } |
mat(0,1)=det*V12[1]; |
1137 |
|
TinyVector<2> bary,secondmb; |
1138 |
// vtkHexahedron* hexahedron = vtkHexahedron::New(); |
secondmb[0]=P0[1]; |
1139 |
|
secondmb[1]=P0[2]; |
1140 |
// vtkUnstructuredGrid* anHexahedraGrid = vtkUnstructuredGrid::New(); |
bary=mat*secondmb; |
1141 |
// anHexahedraGrid->Allocate(m.numberOfCells(),1); |
if(bary[0]>=eps && bary[1]>=eps && (1-bary[0]-bary[1])>=eps) |
1142 |
|
compt+=1; |
1143 |
// for (std::set<const Cell*>::iterator i = hlist.begin(); |
} |
1144 |
// i != hlist.end(); ++i) { |
else |
1145 |
// const CartesianHexahedron& H = static_cast<const CartesianHexahedron&>(*(*i)); |
compt+=1; |
1146 |
// for (size_t j=0; j<8; ++j) |
{ |
1147 |
// hexahedron->GetPointIds()->SetId(j,m.vertexNumber(H(j))); |
det=V02[0]*V12[2]-V02[2]*V12[0]; |
1148 |
|
if(det!=0.) |
1149 |
// anHexahedraGrid->InsertNextCell(hexahedron->GetCellType(), |
{ |
1150 |
// hexahedron->GetPointIds()); |
det=1./det; |
1151 |
// } |
mat(0,0)=-V12[2]*det; |
1152 |
|
mat(1,0)=V02[2]*det; |
1153 |
// anHexahedraGrid->SetPoints(vertices); |
mat(1,1)=-V02[0]*det; |
1154 |
|
mat(0,1)=V12[0]*det; |
1155 |
// vtkDoubleArray* values = vtkDoubleArray::New(); |
TinyVector<2> bary,secondmb; |
1156 |
// values->Resize(m.numberOfVertices()); |
secondmb[0]=P0[0]; |
1157 |
// for (size_t i=0; i<m.numberOfVertices(); ++i) { |
secondmb[1]=P0[2]; |
1158 |
// values->InsertNextValue(1); |
bary=mat*secondmb; |
1159 |
// } |
|
1160 |
|
if(bary[0]>=eps && bary[1]>=eps && (1-bary[0]-bary[1])>=eps) |
1161 |
// anHexahedraGrid->GetPointData()->SetScalars(values); |
{ |
1162 |
|
compt+=1; |
1163 |
// // We create an instance of vtkPolyDataMapper to map the polygonal data |
} |
1164 |
// // into graphics primitives. We connect the output of the cone souece |
} |
1165 |
// // to the input of this mapper |
else |
1166 |
|
compt+=1; |
1167 |
// vtkDataSetMapper* mapper = vtkDataSetMapper::New(); |
} |
1168 |
// mapper->SetInput(anHexahedraGrid); |
} |
1169 |
|
if(compt==3) |
1170 |
// // create an actor to represent the cone. The actor coordinates rendering of |
std::cout<<P.Vector3()[0]<<" "<<P.Vector3()[1]<<" "<<P.Vector3()[2]<<" 3 point intersection \n"; |
1171 |
// // the graphics primitives for a mapper. We set this actor's mapper to be |
|
1172 |
// // coneMapper which we created above. |
} |
1173 |
// // |
|
1174 |
|
|
1175 |
// vtkProperty* prop = vtkProperty::New(); |
void plotmedit(const SurfaceMeshOfTriangles& s_mesh,std::set<const Cell*>& toTreatHexahedra,size_t nobj) |
1176 |
// prop->SetRepresentationToWireframe(); |
{ |
1177 |
|
|
1178 |
// anActor1->SetMapper( mapper ); |
//********************************************************************** |
1179 |
// anActor1->SetProperty(prop); |
|
1180 |
|
|
1181 |
// } |
std::ofstream sortie("intersection.mesh"); |
1182 |
|
|
1183 |
|
sortie<<"MeshVersionFormatted 1"<<" \n"; |
1184 |
// { |
sortie<<" \n"; |
1185 |
// vtkPoints* vertices = vtkPoints::New(); |
sortie<<"Dimension"<<" \n"; |
1186 |
|
sortie<<"3"<<" \n"; |
1187 |
// vertices->SetNumberOfPoints(s.numberOfVertices()); |
sortie<<" \n"; |
1188 |
|
sortie<<"Vertices"<<" \n"; |
1189 |
// for (size_t i=0; i<s.numberOfVertices(); ++i) { |
sortie<<8*toTreatHexahedra.size()+s_mesh.numberOfVertices()<<" \n"; |
1190 |
// const Vertex& X = s.vertex(i); |
for (std::set<const Cell*>::iterator i = toTreatHexahedra.begin(); |
1191 |
// vertices->InsertPoint(i,X[0],X[1],X[2]); |
i != toTreatHexahedra.end(); ++i) |
1192 |
// } |
{ |
1193 |
|
const CartesianHexahedron& H = static_cast<const CartesianHexahedron&>(*(*i)); |
1194 |
// vtkTriangle* triangle = vtkTriangle::New(); |
for (size_t j=0; j<8; ++j) |
1195 |
|
{ |
1196 |
// vtkUnstructuredGrid* aTriangleGrid = vtkUnstructuredGrid::New(); |
sortie<<H(j)[0]<<" "<<H(j)[1]<<" "<<H(j)[2]<<" 0"<<" \n"; |
1197 |
// aTriangleGrid->Allocate(s.numberOfCells(),1); |
} |
1198 |
|
} |
1199 |
// for (size_t i=0; i<s.numberOfCells(); ++i) { |
for(int i=0;i<s_mesh.numberOfVertices();++i) |
1200 |
// const Triangle& T = s.cell(i); |
{ |
1201 |
// triangle->GetPointIds()->SetId(0,s.vertexNumber(T(0))); |
sortie<<s_mesh.vertex(i)[0]<<" "<<s_mesh.vertex(i)[1]<<" "<<s_mesh.vertex(i)[2]<<" 0"<<" \n"; |
1202 |
// triangle->GetPointIds()->SetId(1,s.vertexNumber(T(1))); |
} |
1203 |
// triangle->GetPointIds()->SetId(2,s.vertexNumber(T(2))); |
|
1204 |
|
// for (size_t i=0; i<s_mesh.numberOfCells(); ++i) |
1205 |
// aTriangleGrid->InsertNextCell(triangle->GetCellType(), |
// { |
1206 |
// triangle->GetPointIds()); |
// const Triangle& T = s_mesh.cell(i); |
1207 |
// } |
// sortie<<T(0)[0]<<" "<<T(0)[1]<<" "<<T(0)[2]<<" 0"<<" \n"; |
1208 |
|
// sortie<<T(1)[0]<<" "<<T(1)[1]<<" "<<T(1)[2]<<" 0"<<" \n"; |
1209 |
// aTriangleGrid->SetPoints(vertices); |
// sortie<<T(2)[0]<<" "<<T(2)[1]<<" "<<T(2)[2]<<" 0"<<" \n"; |
1210 |
|
// |
1211 |
// vtkDoubleArray* values = vtkDoubleArray::New(); |
// } |
1212 |
// values->Resize(s.numberOfVertices()); |
sortie<<" \n"; |
1213 |
// for (size_t i=0; i<s.numberOfVertices(); ++i) { |
sortie<<"Triangles"<<"\n"; |
1214 |
// values->InsertNextValue(0); |
sortie<<s_mesh.numberOfCells()<<"\n"; |
1215 |
// } |
|
1216 |
|
for (size_t i=0; i<s_mesh.numberOfCells(); ++i) |
1217 |
// aTriangleGrid->GetPointData()->SetScalars(values); |
{ |
1218 |
|
const Triangle& T = s_mesh.cell(i); |
1219 |
// // We create an instance of vtkPolyDataMapper to map the polygonal data |
sortie<<s_mesh.vertexNumber(T(0))+8*toTreatHexahedra.size()+1<<" "<<s_mesh.vertexNumber(T(1))+8*toTreatHexahedra.size()+1<<" "<<s_mesh.vertexNumber(T(2))+8*toTreatHexahedra.size()+1; |
1220 |
// // into graphics primitives. We connect the output of the cone souece |
// sortie<<3*i+1+8*toTreatHexahedra.size()<<" "<<3*i+2+8*toTreatHexahedra.size()<<" "<<3*i+3+8*toTreatHexahedra.size(); |
1221 |
// // to the input of this mapper |
if(i<(nobj)) |
1222 |
|
sortie<<" 1"<<"\n"; |
1223 |
// vtkDataSetMapper* mapper = vtkDataSetMapper::New(); |
else |
1224 |
// mapper->SetInput(aTriangleGrid); |
sortie<<" 2"<<"\n"; |
1225 |
|
} |
1226 |
|
sortie<<" \n"; |
1227 |
// // create an actor to represent the cone. The actor coordinates rendering of |
sortie<<"Hexahedra"<<"\n"; |
1228 |
// // the graphics primitives for a mapper. We set this actor's mapper to be |
sortie<<toTreatHexahedra.size()<<" \n"; |
1229 |
// // coneMapper which we created above. |
|
1230 |
// // |
/* for (std::set<const Cell*>::iterator i = toTreatHexahedra.begin(); |
1231 |
// anActor2->SetMapper( mapper ); |
i != toTreatHexahedra.end(); ++i) |
1232 |
|
{ |
1233 |
// } |
const CartesianHexahedron& H = static_cast<const CartesianHexahedron&>(*(*i)); |
1234 |
|
for(size_t j=0; j<8; ++j) |
1235 |
// // Create the Renderer and assign actors to it. A renderer is like a |
sortie<<SMesh.vertexNumber(H(j))<<" \n"; |
1236 |
// // viewport. It is part or all of a window on the screen and it is |
}*/ |
1237 |
// // responsible for drawing the actors it has. We also set the background |
for(int i=0;i<toTreatHexahedra.size();i++) |
1238 |
// // color here |
sortie<<8*i+1<<" "<<8*i+2<<" "<<8*i+3<<" "<<8*i+4<<" "<<8*i+5<<" "<<8*i+6<<" "<<8*i+7<<" "<<8*i+8<<" 2"<<"\n"; |
1239 |
// // |
sortie<<"End"<<" \n"; |
1240 |
// // ren1->AddActor( anActor1 ); |
|
1241 |
// ren1->AddActor( anActor2 ); |
} |
1242 |
// ren1->SetBackground( 0.1, 0.2, 0.4 ); |
|
1243 |
|
|
1244 |
// // |
/* #include <vtkPolyDataMapper.h> |
1245 |
// // Finally we create the render window which will show up on the screen |
#include <vtkRenderWindow.h> |
1246 |
// // We put our renderer into the render window using AddRenderer. We also |
#include <vtkRenderWindowInteractor.h> |
1247 |
// // set the size to be 300 pixels by 300 |
#include <vtkTriangle.h> |
1248 |
// // |
#include <vtkHexahedron.h> |
1249 |
// vtkRenderWindow *renWin = vtkRenderWindow::New(); |
#include <vtkTetra.h> |
1250 |
// renWin->AddRenderer( ren1 ); |
#include <vtkUnstructuredGrid.h> |
1251 |
// renWin->SetSize( 300, 300 ); |
#include <vtkDataSetMapper.h> |
1252 |
|
#include <vtkDataSetToPolyDataFilter.h> |
1253 |
// vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New(); |
#include <vtkDoubleArray.h> |
1254 |
// iren->SetRenderWindow(renWin); |
|
1255 |
|
|
1256 |
// // now we loop over 360 degreeees and render the cone each time |
|
1257 |
// // |
void plot2(const SurfaceMeshOfTriangles& s, |
1258 |
// // render the image |
std::set<const Cell*>& hlist, |
1259 |
// renWin->Render(); |
Structured3DMesh& m) |
1260 |
// iren->Start(); |
{ |
1261 |
// // |
vtkRenderer *ren1= vtkRenderer::New(); |
1262 |
// // Free up any objects we created |
|
1263 |
// // |
vtkActor *anActor1 = vtkActor::New(); |
1264 |
// // cone->Delete(); |
vtkActor *anActor2 = vtkActor::New(); |
1265 |
// // coneMapper->Delete(); |
|
1266 |
// // coneActor->Delete(); |
{ |
1267 |
// // ren1->Delete(); |
vtkPoints* vertices = vtkPoints::New(); |
1268 |
// } |
|
1269 |
|
vertices->SetNumberOfPoints(m.numberOfVertices()); |
1270 |
|
|
1271 |
|
for (size_t i=0; i<m.numberOfVertices(); ++i) { |
1272 |
|
const Vertex& X = m.vertex(i); |
1273 |
|
vertices->InsertPoint(i,X[0],X[1],X[2]); |
1274 |
|
} |
1275 |
|
|
1276 |
|
vtkHexahedron* hexahedron = vtkHexahedron::New(); |
1277 |
|
|
1278 |
|
vtkUnstructuredGrid* anHexahedraGrid = vtkUnstructuredGrid::New(); |
1279 |
|
anHexahedraGrid->Allocate(m.numberOfCells(),1); |
1280 |
|
|
1281 |
|
for (std::set<const Cell*>::iterator i = hlist.begin(); |
1282 |
|
i != hlist.end(); ++i) { |
1283 |
|
const CartesianHexahedron& H = static_cast<const CartesianHexahedron&>(*(*i)); |
1284 |
|
for (size_t j=0; j<8; ++j) |
1285 |
|
hexahedron->GetPointIds()->SetId(j,m.vertexNumber(H(j))); |
1286 |
|
|
1287 |
|
anHexahedraGrid->InsertNextCell(hexahedron->GetCellType(), |
1288 |
|
hexahedron->GetPointIds()); |
1289 |
|
} |
1290 |
|
|
1291 |
|
anHexahedraGrid->SetPoints(vertices); |
1292 |
|
|
1293 |
|
vtkDoubleArray* values = vtkDoubleArray::New(); |
1294 |
|
values->Resize(m.numberOfVertices()); |
1295 |
|
for (size_t i=0; i<m.numberOfVertices(); ++i) { |
1296 |
|
values->InsertNextValue(1); |
1297 |
|
} |
1298 |
|
|
1299 |
|
anHexahedraGrid->GetPointData()->SetScalars(values); |
1300 |
|
|
1301 |
|
// We create an instance of vtkPolyDataMapper to map the polygonal data |
1302 |
|
// into graphics primitives. We connect the output of the cone souece |
1303 |
|
// to the input of this mapper |
1304 |
|
|
1305 |
|
vtkDataSetMapper* mapper = vtkDataSetMapper::New(); |
1306 |
|
mapper->SetInput(anHexahedraGrid); |
1307 |
|
|
1308 |
|
// create an actor to represent the cone. The actor coordinates rendering of |
1309 |
|
// the graphics primitives for a mapper. We set this actor's mapper to be |
1310 |
|
// coneMapper which we created above. |
1311 |
|
// |
1312 |
|
|
1313 |
|
vtkProperty* prop = vtkProperty::New(); |
1314 |
|
prop->SetRepresentationToWireframe(); |
1315 |
|
|
1316 |
|
anActor1->SetMapper( mapper ); |
1317 |
|
anActor1->SetProperty(prop); |
1318 |
|
|
1319 |
|
} |
1320 |
|
|
1321 |
|
|
1322 |
|
{ |
1323 |
|
vtkPoints* vertices = vtkPoints::New(); |
1324 |
|
|
1325 |
|
vertices->SetNumberOfPoints(s.numberOfVertices()); |
1326 |
|
|
1327 |
|
for (size_t i=0; i<s.numberOfVertices(); ++i) { |
1328 |
|
const Vertex& X = s.vertex(i); |
1329 |
|
vertices->InsertPoint(i,X[0],X[1],X[2]); |
1330 |
|
} |
1331 |
|
|
1332 |
|
vtkTriangle* triangle = vtkTriangle::New(); |
1333 |
|
|
1334 |
|
vtkUnstructuredGrid* aTriangleGrid = vtkUnstructuredGrid::New(); |
1335 |
|
aTriangleGrid->Allocate(s.numberOfCells(),1); |
1336 |
|
|
1337 |
|
for (size_t i=0; i<s.numberOfCells(); ++i) { |
1338 |
|
const Triangle& T = s.cell(i); |
1339 |
|
triangle->GetPointIds()->SetId(0,s.vertexNumber(T(0))); |
1340 |
|
triangle->GetPointIds()->SetId(1,s.vertexNumber(T(1))); |
1341 |
|
triangle->GetPointIds()->SetId(2,s.vertexNumber(T(2))); |
1342 |
|
|
1343 |
|
aTriangleGrid->InsertNextCell(triangle->GetCellType(), |
1344 |
|
triangle->GetPointIds()); |
1345 |
|
} |
1346 |
|
|
1347 |
|
aTriangleGrid->SetPoints(vertices); |
1348 |
|
|
1349 |
|
vtkDoubleArray* values = vtkDoubleArray::New(); |
1350 |
|
values->Resize(s.numberOfVertices()); |
1351 |
|
for (size_t i=0; i<s.numberOfVertices(); ++i) { |
1352 |
|
values->InsertNextValue(0); |
1353 |
|
} |
1354 |
|
|
1355 |
|
aTriangleGrid->GetPointData()->SetScalars(values); |
1356 |
|
|
1357 |
|
// We create an instance of vtkPolyDataMapper to map the polygonal data |
1358 |
|
// into graphics primitives. We connect the output of the cone souece |
1359 |
|
// to the input of this mapper |
1360 |
|
|
1361 |
|
vtkDataSetMapper* mapper = vtkDataSetMapper::New(); |
1362 |
|
mapper->SetInput(aTriangleGrid); |
1363 |
|
|
1364 |
|
|
1365 |
|
// create an actor to represent the cone. The actor coordinates rendering of |
1366 |
|
// the graphics primitives for a mapper. We set this actor's mapper to be |
1367 |
|
// coneMapper which we created above. |
1368 |
|
// |
1369 |
|
anActor2->SetMapper( mapper ); |
1370 |
|
|
1371 |
|
} |
1372 |
|
|
1373 |
|
// Create the Renderer and assign actors to it. A renderer is like a |
1374 |
|
// viewport. It is part or all of a window on the screen and it is |
1375 |
|
// responsible for drawing the actors it has. We also set the background |
1376 |
|
// color here |
1377 |
|
// |
1378 |
|
// ren1->AddActor( anActor1 ); |
1379 |
|
ren1->AddActor( anActor2 ); |
1380 |
|
ren1->SetBackground( 0.1, 0.2, 0.4 ); |
1381 |
|
|
1382 |
|
// |
1383 |
|
// Finally we create the render window which will show up on the screen |
1384 |
|
// We put our renderer into the render window using AddRenderer. We also |
1385 |
|
// set the size to be 300 pixels by 300 |
1386 |
|
// |
1387 |
|
vtkRenderWindow *renWin = vtkRenderWindow::New(); |
1388 |
|
renWin->AddRenderer( ren1 ); |
1389 |
|
renWin->SetSize( 300, 300 ); |
1390 |
|
|
1391 |
|
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New(); |
1392 |
|
iren->SetRenderWindow(renWin); |
1393 |
|
|
1394 |
|
// now we loop over 360 degreeees and render the cone each time |
1395 |
|
// |
1396 |
|
// render the image |
1397 |
|
renWin->Render(); |
1398 |
|
iren->Start(); |
1399 |
|
// |
1400 |
|
// Free up any objects we created |
1401 |
|
// |
1402 |
|
// cone->Delete(); |
1403 |
|
// coneMapper->Delete(); |
1404 |
|
// coneActor->Delete(); |
1405 |
|
// ren1->Delete(); |
1406 |
|
}*/ |