#include "ContourExtractData.h" //---------------------------------------------------------------------- ContourExtractData::ContourExtractData( bool okImagesResults) { this->imagedata = NULL; imagedataValueResult = NULL; imagedataMaskResult = NULL; this->okImagesResults = okImagesResults; _typeOperation = 0; } // ------------------------------------------------------------------------ ContourExtractData::~ContourExtractData() { } //---------------------------------------------------------------------- void ContourExtractData::SetImage( vtkImageData* imagedata) { this->imagedata = imagedata; if (this->okImagesResults==true){ InitVtkImagesResult(); } } //---------------------------------------------------------------------- void ContourExtractData::SetZtoBeAnalys( int z ) { this->zImage = z; } //------------------------------------------------------------------------ void ContourExtractData::SetLstManualContourModel( std::vector lstManConMod) { this->lstManConMod = lstManConMod; } //------------------------------------------------------------------------ void ContourExtractData::GetMinMaxPoint(int *minPoint, int *maxPoint, manualContourModel *manualcontourmodel ) { int i; //int np = manualcontourmodel->GetSizeLstPoints( ); // number of control points // JPRx // JSTG 26-02-08 --------------------------------------------------------------------------------------- //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline //------------------------------------------------------------------------------------------------------ // JSTG 26-02-08 --------------------------------------------------------------------------------------- //double x,y,z,t; double x,y,z; //double delta=( double ) ( np ) / ( double ) ( nps ); manualcontourmodel->UpdateSpline(); for (i=0; iGetSplinePoint(t,x,y,z); manualcontourmodel->GetSpline_i_Point(i,&x,&y,&z); if (xmaxPoint[0]){ maxPoint[0]=(int)x; } if (y>maxPoint[1]){ maxPoint[1]=(int)y; } } //------------------------------------------------------------------------------------------------------ } //------------------------------------------------------------------------ void ContourExtractData::GetMinMaxPoint_Of_LstManConMod( int *minPoint, int *maxPoint ) { int i,size = lstManConMod.size(); for(i=0 ; iGetSizeLstPoints( ); // number of control points // JPRx // JSTG 26-02-08 --------------------------------------------------------------------------------------- //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline //double x1,y1,z1,x2,y2,z2,t; double x1,y1,z1,x2,y2,z2; double xx1, yy1,xx2, yy2; //double delta=( double ) ( np ) / ( double ) ( nps ); manualcontourmodel->UpdateSpline(); //------------------------------------------------------------------------------------------------------ double d; bool ok; // if (np>=2) // { // JSTG 26-02-08 --------------------------------------------------------------------------------------- nps--; //manualcontourmodel->GetSplinePoint(0,x1,y1,z1); manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1); for (i=1; i<=nps; i++) { ok=false; //t= delta * (double)(i%nps); //manualcontourmodel->GetSplinePoint(t,x2,y2,z2); manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2); //------------------------------------------------------------------------------------------------------ //by triangle similarity if ( ((y1=y1)&&(yy2)&&(y<=y1)&&(y>y2)) ) { if (y1xx2)&&(x<(xx1-d))) ) { result++; } } // if x1=x2; y1=y2; z1=z2; } // for i // } //if return result; } //------------------------------------------------------------------------ bool ContourExtractData::isInside(int x, int y, int typeOperation) { bool result = false; int numberLeft = 0; int i,size = this->lstManConMod.size(); int numberInside = 0; int ext[6]; imagedata->GetExtent(ext); if ((x>=0) && (x<=ext[1]) && (y>=0) && (y<=ext[3])) { if (typeOperation==0) // AND Intersection { for (i=0;iGetVtkBaseData()->GetZ(); //JSTG 13-03-08----- //EED OJO avec JS _zz = z; //------------------ double result; void *p; p = imagedata->GetScalarPointer(x,y,z); if (imagedata->GetScalarType()==VTK_CHAR) { char *pp = (char*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR) { signed char *pp = (signed char*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR) { unsigned char *pp = (unsigned char*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_SHORT) { short *pp = (short*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT) { unsigned short *pp = (unsigned short*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_INT) { int *pp = (int*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT) { unsigned int *pp = (unsigned int*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_LONG) { long *pp = (long*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG) { unsigned long *pp = (unsigned long*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_FLOAT) { float *pp = (float*)p; result = (double)(*pp); } else if (imagedata->GetScalarType()==VTK_DOUBLE) { double *pp = (double*)p; result = (double)(*pp); } return result; } //------------------------------------------------------------------------ void ContourExtractData::PutVtkImageDataResultValue( int x, int y, int z, double value ) { unsigned short *pValue; unsigned short *pMask; pValue = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,z); pMask = (unsigned short *)imagedataMaskResult->GetScalarPointer(x,y,z); *pMask = 255; *pValue = (unsigned short)value; } //------------------------------------------------------------------------ void ContourExtractData::ResetImageResult(int z) { if (okImagesResults==true) { unsigned short *pValue; unsigned short *pMask; pValue = (unsigned short *)imagedataValueResult->GetScalarPointer(0,0,z); pMask = (unsigned short *)imagedataMaskResult->GetScalarPointer(0,0,z); int ext[6]; imagedataValueResult->GetExtent(ext); int i,size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); for(i=0; iModified(); imagedataMaskResult->Modified(); } } //------------------------------------------------------------------------ void ContourExtractData::GetValuesInsideCrown(std::vector *pLstValue, std::vector *pLstValuePosX, std::vector *pLstValuePosY, std::vector *pLstValuePosZ) { pLstValue->clear(); pLstValuePosX->clear(); pLstValuePosY->clear(); pLstValuePosZ->clear(); // if (okImagesResults==true) // { // ResetImageResult(zImage); // } int minPoint[2]; int maxPoint[2]; int i,j; double value; minPoint[0] = 999999; minPoint[1] = 999999; maxPoint[0] = -999999; maxPoint[1] = -999999; GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint); for (j=minPoint[1]; j push_back( value ); pLstValuePosX -> push_back( i ); pLstValuePosY -> push_back( j ); pLstValuePosZ -> push_back( -1 ); } // if } // for } // for // Borrame // if (this->okImagesResults==true){ // imagedataValueResult->Modified(); // imagedataMaskResult->Modified(); // } } //------------------------------------------------------------------------ vtkImageData *ContourExtractData::GetVtkImageValueResult() { return imagedataValueResult; } //------------------------------------------------------------------------ vtkImageData *ContourExtractData::GetVtkImageMaskResult() { return imagedataMaskResult; } // ------------------------------------------------------------------------ void ContourExtractData::InitVtkImagesResult() { int ext[6]; int newDim[3]; double spc[3]; int scalartype; imagedata->GetSpacing(spc); imagedata->GetExtent(ext); newDim[0]=ext[1]-ext[0]+1; newDim[1]=ext[3]-ext[2]+1; newDim[2]=ext[5]-ext[4]+1; scalartype = imagedata->GetScalarType(); if (imagedataValueResult!=NULL) { imagedataValueResult->Delete(); } imagedataValueResult = vtkImageData::New(); // imagedataValueResult->SetScalarType(scalartype); imagedataValueResult->SetScalarTypeToUnsignedShort(); imagedataValueResult->SetSpacing(spc); imagedataValueResult->SetDimensions( newDim ); imagedataValueResult->AllocateScalars(); if (imagedataMaskResult!=NULL) { imagedataMaskResult->Delete(); } imagedataMaskResult = vtkImageData::New(); // imagedataMaskResult->SetScalarType(scalartype); imagedataMaskResult->SetScalarTypeToUnsignedShort(); imagedataMaskResult->SetSpacing(spc); imagedataMaskResult->SetDimensions( newDim ); imagedataMaskResult->AllocateScalars(); } //------------------------------------------------------------------------ void ContourExtractData::Statistics( std::vector *inputLstValue, int grayRangeMin, int grayRangeMax, int *rCountRange, int *rsize, double *rmin, double *rmax, double *raverage, double *rstandardeviation) { double min = 0; double max = 0; double average = 0; double standardeviation = 0; double acum = 0; int size = 0; int countRange = 0; double ng; if (inputLstValue!=NULL) { size=inputLstValue->size(); if (size>0){ max=(*inputLstValue)[0]; min=(*inputLstValue)[0]; // Average , countRange int i; for ( i=0; ing) min=ng; // Min if ((ng>=grayRangeMin) && (ng<=grayRangeMax)) countRange++; // countRange } average = acum / size; // Standar Deviation acum=0; double tmp; for ( i=0; i