X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=bbtk%2Fsrc%2FbbcreaMaracasVisuManualContourModel_Box.cxx;h=8ad078e6d20b6ae2669f8a5a6975edc9ae60e0da;hb=4b2a99534d79424c7892e09160a1488604741064;hp=e1f639297815ece66af07687b09cdfcc11b507c1;hpb=865d74f8d9ea0b80a3bc4de0be2b73d85399c2b5;p=creaMaracasVisu.git diff --git a/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx b/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx index e1f6392..8ad078e 100644 --- a/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx +++ b/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx @@ -15,9 +15,293 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ManualContourModel_Box,bbtk::AtomicBlackBox); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== -void ManualContourModel_Box::Process() + + +void ManualContourModel_Box::ProcessBySegment( + int Type, + int &iGeneral, int sizeSegment, + std::vector *lstInX,std::vector *lstInY, std::vector *lstInZ, + std::vector *lstOutX,std::vector *lstOutY, std::vector *lstOutZ, + std::vector *lstIndexsOut, bool open ) +{ + creaContoursFactory f; + manualContourModel *m; + int i,size=iGeneral+sizeSegment; + double x,y,z; + m = (manualContourModel*)f.getContourModel( bbGetInputType() ); + m->SetNumberOfPointsSpline( bbGetInputNbPoints() ); + m->SetCloseContour( open ); + for (i=iGeneral;iAddPoint( (*lstInX)[i] , (*lstInY)[i] , (*lstInZ)[i] ); + } // for + m->UpdateSpline(); + int sizeContour = bbGetInputNbPoints(); + for (i=0;iGetSpline_i_Point(i,&x,&y,&z); + lstOutX->push_back(x); + lstOutY->push_back(y); + lstOutZ->push_back(z); + } // for + iGeneral=iGeneral+sizeSegment; + lstIndexsOut->push_back( sizeContour ); + delete m; +} + + +void ManualContourModel_Box::RedistributionPoints( std::vector *lstOutX, + std::vector *lstOutY, + std::vector *lstOutZ, + std::vector *lstIndexsOut ) +{ + std::vector lstRstX; + std::vector lstRstY; + std::vector lstRstZ; + int iLstIndexOut,sizeLstIndexOut=lstIndexsOut->size(); + int ii, iGeneral=0; + int size; + for (iLstIndexOut=0; iLstIndexOut2) + { + double dist=0,dist2,distSeg,delta; + double dd,dx,dy,dz; + int i,k; + for (i=iGeneral+1; i=ii*delta) + { + dd=(ii*delta-dist2)/distSeg; + if (distSeg==0) + { + dd=0; + } // if distSeg == 0 + lstRstX.push_back( (*lstOutX)[k-1] + dd*dx ); + lstRstY.push_back( (*lstOutY)[k-1] + dd*dy ); + lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz ); + k=iGeneral+size; + } else { + if (k==iGeneral+size-1) + { + dd=1; + lstRstX.push_back( (*lstOutX)[k-1] + dd*dx ); + lstRstY.push_back( (*lstOutY)[k-1] + dd*dy ); + lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz ); +// printf("EED ManualContourModel_Box::RedistributionPoints iLstIndexOut=%d i=%d k=%d dist2+distSeg=%f ii*delta=%f dif=%f \n", iLstIndexOut,i-iGeneral, k-iGeneral, dist2+distSeg , ii*delta , (dist2+distSeg) - ii*delta); + } + }// if dist2 + dist2=dist2+distSeg; + } // for k + } //for i + if (lstRstX.size()!=size) + { + printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size); + } + for (i=iGeneral; i2 + iGeneral=iGeneral+size; + }// for iLstIndexOut +} + + +void ManualContourModel_Box::ClockwisePoints( std::vector *lstInX, + std::vector *lstInY, + std::vector *lstInZ, + std::vector *lstIndexsIn ) { + int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size(); + int i,iGeneral=0; + int size,size2; + double cx,cy,cz; + double px,py,pz; + double backpx,backpy,backpz; + double ang; + char dir=-1; + bool dirx,diry,dirz; + int flagAng=0; + float backang; + double tmp; + // For each contour + for (iLstIndexIn=0; iLstIndexIn2) // for contour with more than 2 points + { + cx = 0; + cy = 0; + cz = 0; + dirx = true; + diry = true; + dirz = true; + for ( i=0 ; i0) + { + if (backang2 + iGeneral = iGeneral+size; + } // for iLstIndexIn +} + +void ManualContourModel_Box::ShiftValues( std::vector *lstInX, + std::vector *lstInY, + std::vector *lstInZ, + std::vector *lstIndexsIn ) +{ + int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size(); + int ii, iGeneral=0; + int size,size2; + double dist,distMin; + int i,iBack; + double dx,dy,dz; + std::vector LstTmpX; + std::vector LstTmpY; + std::vector LstTmpZ; + if (sizeLstIndexIn>=2) + { + for (iLstIndexIn=0; iLstIndexIn lstIndexsIn=bbGetInputLstIndexsIn(); + std::vector lstIndexsOut; + std::vector lstOutX; + std::vector lstOutY; + std::vector lstOutZ; + if (bbGetInputLstIndexsIn().size()==0) { - m->InsertPoint( bbGetInputLstControlPointsX()[i] , bbGetInputLstControlPointsY()[i] , bbGetInputLstControlPointsZ()[i] ); - } // for - m->UpdateSpline(); - size = bbGetInputNbPoints(); + lstIndexsIn.push_back( lstInX.size() ); + } + if (bbGetInputDoubleContour()==1) + { + ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn ); + ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn ); + } // DoubleContour + int i,size=lstIndexsIn.size(); + int iGeneral=0; for (i=0;iGetSpline_i_Point(i,&x,&y,&z); - lstX.push_back(x); - lstY.push_back(y); - lstZ.push_back(z); + ProcessBySegment( bbGetInputType() , + iGeneral, lstIndexsIn[i] , + &lstInX , &lstInY , &lstInZ, + &lstOutX , &lstOutY , &lstOutZ, + &lstIndexsOut,bbGetInputOpenClose() ); } // for - bbSetOutputLstContourPointsX(lstX); - bbSetOutputLstContourPointsY(lstY); - bbSetOutputLstContourPointsZ(lstZ); - delete m; + if (bbGetInputDoubleContour()==0) + { + //////////////////// Set Out DoubleContour = 0 + bbSetOutputLstContourPointsX(lstOutX); + bbSetOutputLstContourPointsY(lstOutY); + bbSetOutputLstContourPointsZ(lstOutZ); + bbSetOutputLstIndexsOut(lstIndexsOut); + } else { + RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut); + ///////////// Second Step Transpose the vectors + lstInX.clear(); + lstInY.clear(); + lstInZ.clear(); + lstIndexsIn.clear(); + size = bbGetInputNbPoints(); + int j,size2 = lstIndexsOut.size(); + for (i=0;i