30 #include "vsr_graph.h"
40 template<bits::type DIM>
47 typedef typename HEG::Face Face;
48 typedef typename HEG::HalfEdge Edge;
54 vector<
bool> bVisited;
62 (euc::hom( f.a() ) ^ euc::hom (f.b()) ^ euc::hom( f.c() ) ).dual()
68 euc::hom( e.a() ) ^ euc::hom( e.b() )
73 auto
edgePlane( Edge& ea, Edge& eb ) RETURNS (
74 (euc::hom( ea.a() ) ^ euc::hom (ea.b()) ^ euc::hom( eb.a() ) ).dual()
78 template<class DualPlaneType>
81 auto hi = euc::hom(i);
82 auto halfspace = (hi <= dlp)[0];
83 cout << halfspace << endl;
84 if (halfspace < -0.0001 )
return false;
90 bool allTrue( vector<bool> b ){
91 for (
int i = 0;i < b.size(); ++i){
103 HEG& calc ( vector<Type>& group ) {
106 bVisited = vector<bool>( group.size(),
false);
116 HEG& initialFace(vector<Type>& group){
119 bVisited = vector<bool>( group.size(),
false);
121 auto *ta = &group[0];
123 int idxA, idxB, idxC;
126 double min = 1000000;
128 for (
auto& i : group){
130 auto dist = (*ta - i).wt();
141 auto edge = euc::hom(*ta) ^ euc::hom(*tb);
144 for (
auto& i : group){
145 if( (ta!=&i) && (tb!=&i) ){
146 auto plane = (edge ^ euc::hom(i)).dual();
166 graph.add( group[idxA] ); bVisited[idxA] =
true;
167 graph.add( group[idxB] ); bVisited[idxB] =
true;
168 graph.add( group[idxC] ); bVisited[idxC] =
true;
179 HEG& altConvexPass(vector<Type>& group){
181 bool bFoundNew =
true;
182 while ( !allTrue( bVisited ) && bFoundNew ) {
190 auto face =
graph.lastFace();
193 auto& edgeA =
graph.lastEdge();
194 auto& edgeB = *(
graph.lastEdge().next);
196 auto ea = euc::hom(edgeA.a());
197 auto eb = euc::hom(edgeA.b());
198 auto ec = euc::hom(edgeB.a());
200 auto edgeLineA = ea ^ eb;
201 auto edgeLineB = ec ^ ea;
204 VSR_PRECISION min = 0; VSR_PRECISION max = 10000;
int idx;
207 for (
int i = 0; i < group.size(); ++i){
209 if ( !bVisited[i] ) {
211 auto n = euc::hom( group[i] );
214 auto ndlp = (n ^ edgeLineA).dual().unit();
216 VSR_PRECISION convex = (ndlp <= dlp )[0];
229 ndlp = (n ^ edgeLineB).dual().unit();
230 convex = (ndlp <= dlp )[0];
248 if ( !bVisited[idx] && bFoundNew ){
250 if (!bUseEdgeB)
graph.add( group[idx] );
251 else graph.addAt( group[idx], edgeB);
252 bVisited[idx] =
true;
263 for(
int it=0; it < bVisited.size(); ++it){
266 for (
auto& e :
graph.edge() ){
267 auto dlp = (
edgeLine(*e) ^ euc::hom( group[it] ) ).dual();
270 graph.addAt( group[it], *e );
284 HEG& convexPass(vector<Type>& group){
286 bool bFoundNew =
true;
287 while ( !allTrue( bVisited ) && bFoundNew ) {
295 auto face =
graph.lastFace();
298 auto& edgeA =
graph.lastEdge();
299 auto& edgeB = *(
graph.lastEdge().next);
301 auto ea = euc::hom(edgeA.a());
302 auto eb = euc::hom(edgeA.b());
303 auto ec = euc::hom(edgeB.a());
305 auto edgeLineA = ea ^ eb;
306 auto edgeLineB = ec ^ ea;
309 VSR_PRECISION min = 0; VSR_PRECISION max = 10000;
int idx;
311 for (
int i = 0; i < group.size(); ++i){
313 if ( !bVisited[i] ) {
315 auto n = euc::hom( group[i] );
318 auto ndlp = (n ^ edgeLineA).dual().unit();
320 VSR_PRECISION convex = (ndlp <= dlp )[0];
325 VSR_PRECISION dist = fabs( (n <= dlp)[0] );
329 if ( convex > min && dist < max ) {
342 ndlp = (n ^ edgeLineB).dual().unit();
343 convex = (ndlp <= dlp )[0];
347 VSR_PRECISION dist = fabs( (n <= dlp)[0] );
349 if ( convex > min && dist < max ) {
363 if ( !bVisited[idx] && bFoundNew ){
365 if (!bUseEdgeB)
graph.add( group[idx] );
366 else graph.addAt( group[idx], edgeB);
367 bVisited[idx] =
true;
372 for(
int it=0; it < bVisited.size(); ++it){
375 for (
auto& e :
graph.edge() ){
376 auto dlp = (
edgeLine(*e) ^ euc::hom( group[it] ) ).dual();
379 graph.addAt( group[it], *e );
394 HEG& closeHoles(
int N=0){
403 auto& ea = nullEdges[0];
406 auto dlp =
facetPlane( *( ea->face ) ).unit();
413 VSR_PRECISION min = 0;
415 for (
auto& i : nullEdges ){
418 if (ea->node != i->node){
421 if ( ea->isOpp(*i) ) {
428 auto n = euc::hom( i->a() );
429 auto ndlpA = ( n ^ ela ).dual().unit();
430 auto ndlpB = ( ela ^ n ).dual().unit();
431 VSR_PRECISION convex = (ndlpA <= dlp)[0];
432 cout <<
"test convex: " << convex <<
" " << (dlp<=ndlpB)[0] << endl;
436 cout <<
"convex: " << min << endl;
444 bool bTestBoth =
false;
446 if ( ea->ccwFrom( *eb ) ){
448 if ( ea -> triangle() ) {
graph.
close( *ea ); }
450 else {
graph.
close( *ea, *eb ); cout <<
"ccw" << endl; }
451 }
else if (ea->cwFrom( *eb )){
453 if ( ea -> triangle() ) {
graph.
close( *ea ); }
455 else {
graph.
close( *eb, *ea ); cout <<
"cc" << endl; }
459 cout <<
"pt" << endl;
466 for (
auto& i : nullEdges ){
467 if (
graph.edge( -1 ).isOpp(*i) ) {
468 graph.edge( -1 ).seal(*i);
469 cout <<
"suture 1" << endl;
475 for (
auto& i : nullEdges ){
476 if (
graph.edge( -3 ).isOpp(*i) ) {
477 graph.edge( -3 ).seal(*i);
478 cout <<
"suture 2" << endl;
NEVec< DIM+1 > HomType
Homogenized Vector type.
Definition: vsr_hull.h:44
auto edgeLine(Edge &e) -> auto
Make direct line from an edge.
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
vector< HalfEdge * > nullEdges()
Get null edges of graph.
Definition: vsr_graph.h:674
auto facetPlane(Face &f) -> auto
Make dual euclidean plane from a face.
Templated half edge structure (pointers to any type) Navigates references to surface topology of data...
Definition: vsr_graph.h:18
core namespaced operations that are metric-agnostic
HEG graph
The half edge graph.
Definition: vsr_hull.h:51
bool isHalfSpace(DualPlaneType &dlp, vector< Type > &group)
are all members of group in same half space relative to plane?
Definition: vsr_hull.h:79
the versor library namespace
Definition: vsr_algebra.h:29
auto edgePlane(Edge &ea, Edge &eb) -> auto
Make plane from two edges.
convex (and other assorted) hulls assembled into a half edge graph
Definition: vsr_hull.h:41
void close(HalfEdge &ha, HalfEdge &hb)
eb /ea counter clockwise
Definition: vsr_graph.h:434
NEVec< DIM > Type
Vector type.
Definition: vsr_hull.h:43