//-- Alternativa con openmp --
void ManualPaint_Model::LstPointOMPAnalice()
{
+
+printf("EED ManualPaint_Model::LstPointOMPAnalice\n" );
+printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
+printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
+printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
+printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
+
+
+printf("EED ManualPaint_Model::LstPointOMPAnalice Start \n");
//-- Alternativa con openmp --
// A. Create copie of index original list => lst1
// B. if list1 es not empty do..
#pragma omp parallel for
for (i2=0;i2<size2;i2++)
{
-if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) ||
- (k4omp==i2) || (k5omp==i2) || (k6omp==i2) )
-{
- if (size2==1)
- {
- printf(" 100% (just one element)\n");
- } else {
- printf(" %d%\n", (int)(((double)i2/(double)(size2-1))*100 ));
- }
-}// if K#omp
+ if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) ||
+ (k4omp==i2) || (k5omp==i2) || (k6omp==i2) )
+ {
+ if (size2==1)
+ {
+ printf(" 100% (just one element)\n");
+ } else {
+ printf(" %d% \n", (int)(((double)i2/(double)(size2-1))*100 ));
+ }
+ }// if K#omp
manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[ lst2[i2] ] ,
bbGetInputByLstPointsY()[ lst2[i2] ] ,
bbGetInputByLstPointsZ()[ lst2[i2] ] );
} // for i2
} // while
+printf("EED ManualPaint_Model::LstPointOMPAnalice End\n");
}
void ManualPaint_Model::Process()
{
-
+printf("EED ManualPaint_Model::Process Start\n");
/* Notas
0. Quitar comentarion ByLstPoints openmp
1. Falta openmp ByImagePoints
*/
if (bbGetInputActive()==true)
{
+printf("EED ManualPaint_Model::Process 1\n");
if (bbGetInputImage()!=NULL)
{
+printf("EED ManualPaint_Model::Process 2\n");
manualpaintmodel->SetActive( bbGetInputActive() );
manualpaintmodel->SetTool( bbGetInputTool() );
manualpaintmodel->Set2D3D( bbGetInput2D3D() );
+printf("EED ManualPaint_Model::Process 2.1\n");
manualpaintmodel->SetImages( bbGetInputImage(),bbGetInputImage2() );
+printf("EED ManualPaint_Model::Process 2.2\n");
manualpaintmodel->SetGrayLevel( bbGetInputGrayLevel() );
manualpaintmodel->SetDirection( bbGetInputDirection() );
manualpaintmodel->SetBrushSize( bbGetInputBrushSize() );
manualpaintmodel->SetRangeMax( bbGetInputRange()[1] );
if (bbGetInputPoint().size()==3)
{
+printf("EED ManualPaint_Model::Process 3\n");
manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
manualpaintmodel->SetUndoImage();
} // if Points
if ( bbGetInputByLstPointsX().size()!=0 )
{
+printf("EED ManualPaint_Model::Process 4\n");
//-- Alternativa con openmp --
- LstPointOMPAnalice();
+// LstPointOMPAnalice();
- /* -- Original ByLstPoints sin openmp --
+// /* -- Original ByLstPoints sin openmp --
int i,size = bbGetInputByLstPointsX().size();
+long int k1omp=(double)(size-1)*0.0;
+long int k2omp=(double)(size-1)*0.2;
+long int k3omp=(double)(size-1)*0.4;
+long int k4omp=(double)(size-1)*0.6;
+long int k5omp=(double)(size-1)*0.8;
+long int k6omp=(double)(size-1)*1.0;
+printf("EED ManualPaint_Model::Process list of points (with openmp) size=%d\n",size);
+#pragma omp parallel for
for (i=0;i<size;i++)
{
+ if ( (k1omp==i) || (k2omp==i) || (k3omp==i) ||
+ (k4omp==i) || (k5omp==i) || (k6omp==i) )
+ {
+ if (size==1)
+ {
+ printf(" 100% (just one element)\n");
+ } else {
+ printf(" %d% \n", (int)(((double)i/(double)(size-1))*100 ));
+ }
+ }// if K#omp
manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] ,
bbGetInputByLstPointsY()[i] ,
bbGetInputByLstPointsZ()[i] );
//_manualPaintModel->SetUndoImage(); // Probably needed. Here is ok.
} // for
- -- Original ByLstPoints sin openmp --*/
+// -- Original ByLstPoints sin openmp --*/
+
+ manualpaintmodel->Copy_GeneralAuxFill_to_Results();
}// if ByLstPointsX
if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
int dimZ=ext[5]-ext[4]+1;
DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
+
+ long int index, size=dimX*dimY*dimZ;
+
+long int k1omp=(double)(size-1)*0.0;
+long int k2omp=(double)(size-1)*0.2;
+long int k3omp=(double)(size-1)*0.4;
+long int k4omp=(double)(size-1)*0.6;
+long int k5omp=(double)(size-1)*0.8;
+long int k6omp=(double)(size-1)*1.0;
+printf("EED ManualPaint_Model::Process ByImagePoints (with openmp) size=%d\n",size);
+#pragma omp parallel for
+ for (index=0; index<size; index++)
+ {
+ if ( (k1omp==index) || (k2omp==index) || (k3omp==index) ||
+ (k4omp==index) || (k5omp==index) || (k6omp==index) )
+ {
+ if (size==1)
+ {
+ printf(" 100% (just one element)\n");
+ } else {
+ printf(" %d% \n", (int)(((double)index/(double)(size-1))*100 ));
+ }
+ }// if K#omp
+ double value1;
+ GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
+ if (value1>0)
+ {
+ double value2;
+ GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
+ if (value2==0)
+ {
+ int i = index % dimX;
+ int j = (index % (dimX*dimY)) / dimX;
+ int k = index / (dimX*dimY);
+ manualpaintmodel->PaintImage(i,j,k);
+// manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
+ } // vI2
+ } // vBIP
+ } // for index
+ manualpaintmodel->Copy_GeneralAuxFill_to_Results();
+
+/*
int i,j,k;
//#pragma omp parallel for
for (k=0;k<dimZ;k++)
{
- if (k%50==0)
- {
- printf("ManualPaint_Model %d%\n", (int)(k*100.0/dimZ) );
- }
for (j=0;j<dimY;j++)
{
for (i=0;i<dimX;i++)
}// for i
}// for j
}// for k
- printf("ManualPaint_Model %d%\n", 100 );
//------- Original ByImagePoints sin openmp-------- */
+
+
} // if ByImagePoints
} else {
bbSetOutputOut( NULL );
}
bbSetOutputManualpaintmodel( manualpaintmodel );
+
+printf("EED ManualPaint_Model::Process End\n");
}
//=====
// 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)
bbSetInputToleranceFill(50);
bbSetInputDistanceFill(25);
std::vector<int> point;
- point.push_back(0);
- point.push_back(0);
- point.push_back(0);
- bbSetInputPoint(point);
+// point.push_back(0);
+// point.push_back(0);
+// point.push_back(0);
+// bbSetInputPoint(point);
std::vector<double> range;
range.push_back(0);
range.push_back(200);
FillFilter::FillFilter()
{
- _tolerancefill = 125;
-
+ _tolerancefill = 125;
+ _GeneralAuxImageFill = NULL;
//EED 2020-04-28 BORRAME Change to local variables to use with openmp
// _auxImageFill = NULL;
// _maxXback = 0;
_maxZback = _maxZ;
*/
+ if (_GeneralAuxImageFill != NULL)
+ {
+ _GeneralAuxImageFill->Delete();
+ }
+ _GeneralAuxImageFill = vtkImageData::New();
+ _GeneralAuxImageFill->SetDimensions(_dimX,_dimY,_dimZ );
+ _GeneralAuxImageFill->SetOrigin(0, 0, 0);
+ _GeneralAuxImageFill->SetExtent(0, _dimX-1, 0, _dimY-1, 0, _dimZ-1);
+ _GeneralAuxImageFill->AllocateScalars(VTK_UNSIGNED_CHAR,1);
+ unsigned char *ptrAuxImageFill = (unsigned char*)_GeneralAuxImageFill->GetScalarPointer();
+ memset(ptrAuxImageFill, 0, _dimX*_dimY*_dimZ*sizeof(unsigned char) );
}
-
-
-
//---------------------------------------------------------------------------
-void FillFilter::Run() // virtual
+void FillFilter::Run(int px, int py, int pz) // virtual
{
long int ivi;
if ((_px >= _minX) && (_px < _dimX) && (_py >= _minY) && (_py < _dimY)
&& (_pz >= _minZ) && (_pz < _dimZ))
{
this->_IMManager->BaseInitialPoint(_px, _py ,_pz);
- FillToolLoop(_px, _py, _pz);
- } //if _minX _maxX _minY _maxY _minZ _maxZ
+// FillToolLoop(_px, _py, _pz);
+ FillToolLoop(px, py, pz);
+
+
+
+ } //if _minX _maxX _minY _maxY _minZ _maxZ
}
//---------------------------------------------------------------------------
-vtkImageData* FillFilter::GenerateAuxImageFill( long int &OneColumnAux, long int &OneLineAux , long int &OnePlaneAux,
- int px,int py,int pz,
- int &pxAux, int &pyAux, int &pzAux )
+vtkImageData* FillFilter::CreateAuxImageFill( long int &OneColumnAux, long int &OneLineAux , long int &OnePlaneAux,
+ int px, int py, int pz,
+ int &pxAux, int &pyAux, int &pzAux,
+ int &minXAux, int &minYAux, int &minZAux )
{
// _2D3D = 1 3D
- int minXAux = px-_distancefill; if (minXAux>=0) { pxAux=px-minXAux; } else { pxAux=px; minXAux=0; }
- int minYAux = py-_distancefill; if (minYAux>=0) { pyAux=py-minYAux; } else { pyAux=py; minYAux=0; }
- int minZAux = pz-_distancefill; if (minZAux>=0) { pzAux=pz-minZAux; } else { pzAux=pz; minZAux=0; }
+ minXAux = px-_distancefill; if (minXAux>=0) { pxAux=px-minXAux; } else { pxAux=px; minXAux=0; }
+ minYAux = py-_distancefill; if (minYAux>=0) { pyAux=py-minYAux; } else { pyAux=py; minYAux=0; }
+ minZAux = pz-_distancefill; if (minZAux>=0) { pzAux=pz-minZAux; } else { pzAux=pz; minZAux=0; }
int maxXAux = px+_distancefill; if (maxXAux>_dimX) { maxXAux=_dimX; }
int maxYAux = py+_distancefill; if (maxYAux>_dimY) { maxYAux=_dimY; }
auxImageFill = vtkImageData::New();
auxImageFill->SetDimensions(auxDimX, auxDimY, auxDimZ);
auxImageFill->SetOrigin(0, 0, 0);
- auxImageFill->SetExtent(0, auxDimX, 0, auxDimY, 0, auxDimZ);
+ auxImageFill->SetExtent(0, auxDimX-1, 0, auxDimY-1, 0, auxDimZ-1);
auxImageFill->AllocateScalars(VTK_UNSIGNED_CHAR,1);
unsigned char * ptrAuxImageFill = (unsigned char *)auxImageFill->GetScalarPointer();
memset( ptrAuxImageFill, 0, auxDimX*auxDimY*auxDimZ );
return auxImageFill;
}
+void FillFilter::Copy_AuxImageFill_To_GeneralAuxFill(int minXAux, int minYAux, int minZAux, vtkImageData *auxImageFill)
+{
+ // copy information from the litle image auxImageFill to the big image _GeneralAuxImageFill
+ DEF_POINTER_IMAGE_VTK_CREA(vAuxImageFill,ssAuxImageFill,pAuxImageFill,stAuxImageFill,auxImageFill)
+ DEF_POINTER_IMAGE_VTK_CREA(v_GeneralAuxImageFill,ss_GeneralAuxImageFill,p_GeneralAuxImageFill,st_GeneralAuxImageFill,_GeneralAuxImageFill)
+ int ext[6];
+ auxImageFill->GetExtent(ext);
+ int auxDimX = ext[1]-ext[0]+1;
+ int auxDimY = ext[3]-ext[2]+1;
+ int auxDimZ = ext[5]-ext[4]+1;
+ int i,j,k;
+ long int indexAux=0;
+ long int indexGeneralAux;
+ for (k=0;k<auxDimZ;k++)
+ {
+ for (j=0;j<auxDimY;j++)
+ {
+ indexGeneralAux=minXAux + (minYAux+j)*_OneLine + (minZAux+k)*_OnePlane;
+// indexAux = j*OneLineAux + k*OnePlaneAux;
+ for (i=0;i<auxDimX;i++)
+ {
+ GETVALUE2_VTK_CREA(vAuxImageFill,pAuxImageFill,stAuxImageFill,indexAux)
+ indexAux++;
+ if (vAuxImageFill==1)
+ {
+ SETVALUE2_VTK_CREA(vAuxImageFill,p_GeneralAuxImageFill,st_GeneralAuxImageFill,indexGeneralAux)
+ } // if vAuxImageFill
+ indexGeneralAux = indexGeneralAux+_OneColumn;
+ } // for i
+ } // for j
+ } // for k
+}
+
+void FillFilter::Copy_GeneralAuxFill_to_Results()
+{
+ DEF_POINTER_IMAGE_VTK_CREA(v_GeneralAuxImageFill,ss_GeneralAuxImageFill,p_GeneralAuxImageFill,st_GeneralAuxImageFill,_GeneralAuxImageFill)
+ long int i,size = _dimX*_dimY*_dimZ;
+ if (_image2==NULL)
+ {
+ DEF_POINTER_IMAGE_VTK_CREA(v_image,ss_image,p_image,st_image,_image)
+// DEF_POINTER_IMAGE_VTK_CREA_set(v_image,ss_image,p_image,st_image,_image)
+#pragma omp parallel for
+ for (i=0;i<size;i++)
+ {
+ int value;
+ GETVALUE2_VTK_CREA(value,p_GeneralAuxImageFill,st_GeneralAuxImageFill,i)
+ if (value!=0)
+ {
+ SETVALUE2_VTK_CREA(_graylevel,p_image,st_image,i)
+ } // if v_GeneralAuxImageFill
+ } // for
+ } else {
+ DEF_POINTER_IMAGE_VTK_CREA(v_image2,ss_image2,p_image2,st_image2,_image2)
+// DEF_POINTER_IMAGE_VTK_CREA_set(v_image2,ss_image2,p_image2,st_image2,_image2)
+#pragma omp parallel for
+ for (i=0;i<size;i++)
+ {
+ int value;
+ GETVALUE2_VTK_CREA(value,p_GeneralAuxImageFill,st_GeneralAuxImageFill,i)
+ if (value!=0)
+ {
+ SETVALUE2_VTK_CREA(_graylevel,p_image2,st_image2,i)
+ } // if v_GeneralAuxImageFill
+ } // for
+ }// if _image2
+
+
+}
+
//---------------------------------------------------------------------------
void FillFilter::FillToolLoop(int px, int py, int pz)
{
- _distbasefill = _distancefill * _distancefill;
+ double distbasefill;
+ double graylevelbasefill;
+ double tmpiglfill;
+ double tmpiglfill2;
+ bool auxGrayLevelValidationFill;
+
+
+
+ distbasefill = _distancefill * _distancefill;
double difX,difY,difZ,_tmpDistfill;
std::vector<int> lstX;
std::vector<int> lstY;
std::vector<long long int> lstivi;
lstivi.push_back( px + py*_OneLine+ pz*_OnePlane );
- long int OneColumnAux, OneLineAux, OnePlaneAux;
- int pxAux, pyAux, pzAux;
- vtkImageData* auxImageFill = GenerateAuxImageFill( OneColumnAux,OneLineAux,OnePlaneAux,
+ long int OneColumnAux, OneLineAux, OnePlaneAux; // how to jump in the little image auxImageFill
+ int pxAux, pyAux, pzAux; // position inside little image auxImageFill
+ int minXAux, minYAux, minZAux; // Where start the little image auxImageFill in the big image
+ vtkImageData* auxImageFill = CreateAuxImageFill( OneColumnAux,OneLineAux,OnePlaneAux,
px,py,pz,
- pxAux,pyAux,pzAux );
+ pxAux,pyAux,pzAux,
+ minXAux,minYAux,minZAux );
std::vector<long long int> lstiviAux;
lstiviAux.push_back( pxAux + pyAux*OneLineAux + pzAux*OnePlaneAux );
+ DEF_POINTER_IMAGE_VTK_CREA(v_image,ss_image,p_image,st_image,_image)
+// DEF_POINTER_IMAGE_VTK_CREA_set(v_image,ss_image,p_image,st_image,_image)
+
+ double v_image2;
+ int ss_image2;
+ char *p_image2;
+ int st_image2;
+
- DEF_POINTER_IMAGE_VTK_CREA_set(v_image,ss_image,p_image,st_image,_image)
if (_image2!=NULL)
{
+// DEF_POINTER_IMAGE_VTK_CREA(v_image2,ss_image2,p_image2,st_image2,_image2)
DEF_POINTER_IMAGE_VTK_CREA_set(v_image2,ss_image2,p_image2,st_image2,_image2)
} // if _image2
- GETVALUE2_VTK_CREA(_graylevelbasefill,p_image,st_image,lstivi[0])
+ GETVALUE2_VTK_CREA(graylevelbasefill,p_image,st_image,lstivi[0])
//EED 2020-04-28 BORRAME Change to local variables to use with openmp
// DEF_POINTER_IMAGE_VTK_CREA(v_auxImageFill,ss_auxImageFill,p_auxImageFill,st_auxImageFill,_auxImageFill)
difZ = pz-lstZ[0];
_tmpDistfill = difX*difX + difY*difY + difZ*difZ;
// if distance of center point
- if (_tmpDistfill<=_distbasefill)
+ if (_tmpDistfill<=distbasefill)
{
// if point not visited
GETVALUE2_VTK_CREA(vAuxImageFill,pAuxImageFill,stAuxImageFill,lstiviAux[0] );
// If Gray Level valid
//EED01
- // _tmpiglfill = _image->GetScalarComponentAsDouble(px, py, pz, 0);
- GETVALUE2_VTK_CREA(_tmpiglfill,p_image,st_image,lstivi[0])
+ // tmpiglfill = _image->GetScalarComponentAsDouble(px, py, pz, 0);
+ GETVALUE2_VTK_CREA(tmpiglfill,p_image,st_image,lstivi[0])
if (_image2!=NULL)
{
//EED01
- // _tmpiglfill2 = _image2->GetScalarComponentAsDouble(px, py, pz, 0);
- GETVALUE2_VTK_CREA(_tmpiglfill2,p_image2,st_image2,lstivi[0])
+ // tmpiglfill2 = _image2->GetScalarComponentAsDouble(px, py, pz, 0);
+ GETVALUE2_VTK_CREA(tmpiglfill2,p_image2,st_image2,lstivi[0])
} else {
- _tmpiglfill2 = _tmpiglfill;
+ tmpiglfill2 = tmpiglfill;
}
- float grayLBFMTOL = _graylevelbasefill - _tolerancefill;
- float grayLBFPTOL = _graylevelbasefill + _tolerancefill;
+ float grayLBFMTOL = graylevelbasefill - _tolerancefill;
+ float grayLBFPTOL = graylevelbasefill + _tolerancefill;
bool isInRange = false;
//DFCH
if (_RangeMin <= grayLBFMTOL && _RangeMax >= grayLBFPTOL) {
grayLBFPTOL = _RangeMax;
isInRange = true;
} //fi esle
- else if ((_RangeMin <= _graylevelbasefill) && (_graylevelbasefill <= _RangeMax)) {
+ else if ((_RangeMin <= graylevelbasefill) && (graylevelbasefill <= _RangeMax)) {
grayLBFMTOL = _RangeMin;
grayLBFPTOL = _RangeMax;
isInRange = true;
if (isInRange)
{
- _auxGrayLevelValidationFill = (_tmpiglfill != _graylevel) &&
- (_tmpiglfill2 != _graylevel) &&
- (_tmpiglfill >= grayLBFMTOL) &&
- (_tmpiglfill <= grayLBFPTOL) &&
- (_tmpDistfill <= _distbasefill) ; //DFCH
+ auxGrayLevelValidationFill = (tmpiglfill != _graylevel) &&
+ (tmpiglfill2 != _graylevel) &&
+ (tmpiglfill >= grayLBFMTOL) &&
+ (tmpiglfill <= grayLBFPTOL) &&
+ (_tmpDistfill <= distbasefill) ; //DFCH
} else {
- _auxGrayLevelValidationFill = false;
+ auxGrayLevelValidationFill = false;
} // if isInRange
- if (_auxGrayLevelValidationFill==true)
+ if (auxGrayLevelValidationFill==true)
{
this->_IMManager->AddModifiedPixel(lstX[0], lstY[0], lstZ[0]); //DFCH
+/*
// Modifie image
if (_image2!=NULL)
{
SETVALUE2_VTK_CREA(_graylevel,p_image,st_image,lstivi[0])
} // if _image2
+*/
+ // Add point to already visited
+ SETVALUE2_VTK_CREA(1,pAuxImageFill,stAuxImageFill,lstiviAux[0]);
+
// Add neighborhood points in the list
- // Add point to already visited
- SETVALUE2_VTK_CREA(1,pAuxImageFill,stAuxImageFill,lstiviAux[0]);
if (_2D3D == 0) //2D
{
lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]+1); lstivi.push_back(lstivi[0]+_OnePlane); lstiviAux.push_back(lstiviAux[0]+OnePlaneAux);
lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]-1); lstivi.push_back(lstivi[0]-_OnePlane); lstiviAux.push_back(lstiviAux[0]-OnePlaneAux);
} // 2D 3D
- } // if gray level valid _auxGrayLevelValidationFill
+ } // if gray level valid auxGrayLevelValidationFill
} // if point not visited
- } // if distance of center point
+ } // if distance of center point
} // if point inside image
// Remove point from the list
lstX.erase( lstX.begin() );
lstivi.erase( lstivi.begin() );
lstiviAux.erase( lstiviAux.begin() );
} // while _lstX.size
+
+ Copy_AuxImageFill_To_GeneralAuxFill( minXAux, minYAux, minZAux, auxImageFill );
+
auxImageFill->Delete();
}