10 #include <TRotation.h>
17 mEdgeTotalOwnerCountOk(
true), mEdgeSimpleSharingOk(
true)
29 std::vector<EicStlVertex*> ¤t = ngroups[ngroups.size()-1];
30 current.push_back(vtx);
43 if (!tolerance)
return;
54 std::multimap<double, EicStlVertex*>::iterator xLower =
xCoord.lower_bound(xMin);
55 std::multimap<double, EicStlVertex*>::iterator xUpper =
xCoord.upper_bound(xMax);
56 for(std::multimap<double, EicStlVertex*>::iterator ix = xLower; ix != xUpper; ix++) {
65 std::multimap<double, EicStlVertex*>::iterator xLower =
yCoord.lower_bound(xMin);
66 std::multimap<double, EicStlVertex*>::iterator xUpper =
yCoord.upper_bound(xMax);
67 for(std::multimap<double, EicStlVertex*>::iterator ix = xLower; ix != xUpper; ix++) {
76 std::multimap<double, EicStlVertex*>::iterator xLower =
zCoord.lower_bound(xMin);
77 std::multimap<double, EicStlVertex*>::iterator xUpper =
zCoord.upper_bound(xMax);
78 for(std::multimap<double, EicStlVertex*>::iterator ix = xLower; ix != xUpper; ix++) {
90 if (iq->second != 3)
continue;
93 double dist = (qtx3d - vtx3d).Mag();
94 if (dist < tolerance) {
95 printf(
" ... %d %f\n", iq->second, dist);
103 std::vector<std::vector<EicStlVertex*> > ngroups;
114 std::vector<EicStlVertex*> gr;
115 ngroups.push_back(gr);
121 for(
unsigned iq=0; iq<ngroups.size(); iq++) {
125 for(
unsigned iv=0; iv<ngroups[iq].size(); iv++) {
132 vsum *= 1.0/ngroups[iq].size();
137 double buffer[3] = {vsum[0], vsum[1], vsum[2]};
142 (*mVertices)[vnew->
key()] = vnew;
150 for(
unsigned iv=0; iv<ngroups[iq].size(); iv++) {
165 for(
unsigned fc=0; fc<
mFbuffer.size(); fc++) {
176 (*mFacets)[facet->
key()] = facet;
180 mFacets->find(facet->
key())->second->IncrementCounter();
201 for (fEntry::iterator fc=
mFacets->begin(); fc!=
mFacets->end(); fc++) {
204 for(vEntry::const_iterator vt=facet->
vertices()->begin(); vt!=facet->
vertices()->end() ; vt++)
205 vt->second->AddFacet(facet);
213 for (fEntry::iterator fc=
mFacets->begin(); fc !=
mFacets->end(); fc++) {
218 unsigned counter = 0;
219 for(vEntry::const_iterator vt=facet->
vertices()->begin(); vt!=facet->
vertices()->end() ; vt++)
220 vv[counter++] = vt->second;
227 for(
unsigned iq=0; iq<3; iq++) {
231 (*mEdges)[edge->
key()] = edge;
233 ee[iq] = (*mEdges)[edge->
key()];
240 for(
unsigned iq=0; iq<3; iq++)
244 for (eEntry::iterator ee=
mEdges->begin(); ee !=
mEdges->end(); ee++) {
247 unsigned owner_counter = 0;
248 for(
unsigned fc=0; fc<edge->
facets().size(); fc++)
249 owner_counter += edge->
facets()[fc]->GetCounter();
251 if (owner_counter%2) {
252 printf(
"-> %d\n", owner_counter);
254 for (vEntry::const_iterator vt=edge->
vertices()->begin(); vt!=edge->
vertices()->end(); vt++) {
277 current->AddFacet(facet, flip);
284 for(
unsigned iq=0; iq<3; iq++) {
286 bool orientation = iq <= 1;
288 if (edge->
facets().size() == 2) {
289 for(
unsigned fc=0; fc<edge->
facets().size(); fc++) {
294 bool edge_orientations_match =
true;
297 for(
unsigned ie=0; ie<3; ie++) {
299 bool other_orientation = ie <= 1;
301 if (other_edge == edge) {
302 edge_orientations_match = orientation != other_orientation;
308 bool other_flip = (flip && edge_orientations_match) ||
309 (!flip && !edge_orientations_match);
319 TVector3
v1 = TVector3(edge->
vertices()-> begin()->second->key()->GetData());
320 TVector3
v2 = TVector3(edge->
vertices()->rbegin()->second->key()->GetData());
321 TVector3 axis = (v2 -
v1).Unit();
323 TVector3 n0 = (flip ? 1.0 : -1.0)*facet->
GetNormal();
324 TVector3 n02d = (n0 - n0.Dot(axis)*axis).Unit();
327 for(
unsigned fc=0; fc<edge->
facets().size(); fc++) {
332 bool edge_orientations_match =
true;
335 for(
unsigned ie=0; ie<3; ie++) {
337 bool other_orientation = ie <= 1;
339 if (other_edge == edge) {
341 edge_orientations_match = orientation != other_orientation;
347 bool other_flip = (flip && edge_orientations_match) ||
348 (!flip && !edge_orientations_match);
350 TVector3 n1 = (other_flip ? 1.0 : -1.0)*other_facet->
GetNormal();
351 TVector3 n12d = (n1 - n1.Dot(axis)*axis).Unit();
353 double alfa = acos(n12d.Dot(n02d));
354 printf(
"alfa: %f\n", (180.0/TMath::Pi())*alfa);
356 TRotation
rp, rm; rp.Rotate(alfa, axis); rm.Rotate(-alfa, axis);
357 TVector3 dp = rp * n12d - n02d, dm = rm * n12d - n02d;
384 printf(
"EicStlMediaGroup::SplitIntoAssemblies() -> ok#1\n");
390 printf(
"EicStlMediaGroup::SplitIntoAssemblies() -> ok#2\n");
410 std::multimap<double, EicStlVertex*> distances;
417 printf(
"distances size: %d\n", distances.size());
420 for( ; distances.size(); ) {
425 printf(
"distance: %f\n", distances.rbegin()->first);
430 TVector3 nv = TVector3(vtx->
key()->
GetData()).Unit();
436 std::multimap<double, EicStlFacet*> diffs;
437 for(std::set<EicStlFacet*>::iterator fc = vtx->
facets().begin(); fc != vtx->
facets().end(); fc++) {
442 double scal = fabs(nv.Dot(facet->
GetNormal()));
445 diffs.insert(std::pair<double, EicStlFacet*>(scal, facet));
449 assert(diffs.size());
469 for(std::multimap<double, EicStlVertex*>::iterator vt=distances.begin();
470 vt!=distances.end(); ) {
473 bool free_facets_exist =
false;
474 for(std::set<EicStlFacet*>::iterator fc = vtx->
facets().begin(); fc != vtx->
facets().end(); fc++) {
478 free_facets_exist =
true;
483 if (!free_facets_exist) {
485 distances.erase(vt++);
496 for(
unsigned ass=0; ass<
mAssemblies.size(); ass++) {
499 printf(
"#%02d: %5d facet(s)\n", ass, assembly->
facets().size());