Program: wxMaracas
Module: $RCSfile: CutModelData.cxx,v $
Language: C++
- Date: $Date: 2009/09/01 14:01:36 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2009/10/16 15:17:56 $
+ Version: $Revision: 1.4 $
Copyright: (c) 2002, 2003
License:
** Start of the manager class
**/
CutModelData::CutModelData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img){
+
+ initializeData(id, interactor, observer, img);
+
+}
+CutModelData::CutModelData(){
+
+}
+void CutModelData::initializeData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img){
_id = id;
_currentshape=0;
createBoxWidget(interactor, observer);
createShapes();
ChangeShape(0);
checkInvariant();
-
-
}
CutModelData::~CutModelData(){
checkInvariant();
_boxWidgetVolume = vtkBoxWidget::New();
_boxWidgetVolume->SetInteractor( interactor );
- //_boxWidgetVolume->SetPlaceFactor(2);
+ //_boxWidgetVolume->SetPlaceFactor(1);
//_boxWidgetVolume->SetInput( img );
//_boxWidgetVolume->PlaceWidget();
+
_boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent , observer );
_boxWidgetVolume->AddObserver( vtkCommand::StartInteractionEvent , observer );
_boxWidgetVolume->AddObserver( vtkCommand::RightButtonReleaseEvent , observer );
int *ext = img->GetExtent();
double *spc = img->GetSpacing();
+
matrix->SetElement(0,0,(ext[1]-ext[0])/4*spc[0]);
matrix->SetElement(1,1,(ext[3]-ext[2])/4*spc[1]);
- matrix->SetElement(2,2,(ext[5]-ext[4])/4*spc[2]);
- matrix->SetElement(0,3,(ext[1]-ext[0])/2*spc[0]);
- matrix->SetElement(1,3,(ext[3]-ext[2])/2*spc[1]);
- matrix->SetElement(2,3,(ext[5]-ext[4])/2*spc[2]);
+ matrix->SetElement(2,2,(ext[5]-ext[4])/4*spc[2]);
+
+ double orgx = (ext[1]-ext[0])/2*spc[0];
+ double orgy = (ext[3]-ext[2])/2*spc[1];
+ double orgz = (ext[5]-ext[4])/2*spc[2];
+
+ matrix->SetElement(0,3,orgx);
+ matrix->SetElement(1,3,orgy);
+ matrix->SetElement(2,3,orgz);
+
currentmatrix->SetMatrix(matrix);
_boxWidgetVolume->SetTransform(currentmatrix);
throw CutModelException("Shape type not found");
}
}
-void CutModelData::ExecuteCut( double* range, bool isinside, vtkImageData* copyimage)
+void CutModelData::ExecuteCut( double* range, bool isinside, vtkImageData* copyimage)throw( CutModelException)
{
wxBusyCursor wait;
CutModelFigure* actualCuttingModel = getCurentCuttingModel();
+ //_boxWidgetVolume->GetTransform(currentmatrix);
actualCuttingModel->SetVtkTransform(getModelTransform(copyimage));
+ //actualCuttingModel->SetVtkTransform(currentmatrix);
actualCuttingModel->SetInversVtkTransform(getModelTransformInvers());
bool inside;
}
-vtkTransform* CutModelData::getModelTransform(vtkImageData* copyimage){
+void CutModelData::ExecuteUnCut(bool isinside, vtkImageData* image, vtkImageData* copyimage)throw( CutModelException)
+{
- vtkMatrix4x4* matrix = currentmatrix->GetMatrix();
- vtkMatrix4x4* matrixmodel = modeltransform->GetMatrix();
+ wxBusyCursor wait;
- double *spc = copyimage->GetSpacing();
+ CutModelFigure* actualCuttingModel = getCurentCuttingModel();
+
+ actualCuttingModel->SetVtkTransform(getModelTransform(copyimage));
+
+ actualCuttingModel->SetInversVtkTransform(getModelTransformInvers());
- modeltransform->Identity();
+ bool inside;
+ bool volInt, volExt;
+ int xx,yy,zz;
+ unsigned short* pOrg;
+ int ext[6];
+ double spc[3];
+ long int contAfter = 0;
+ long int contBefor = 0;
+
+ double value;
+
- double* orient = currentmatrix->GetOrientationWXYZ();
- modeltransform->RotateWXYZ(orient[0],orient[1],orient[2],orient[3]);
+
+ copyimage->GetExtent(ext);
+
+ for (xx=ext[0];xx<ext[1]; xx++)
+ {
+ for (yy=ext[2];yy<ext[3]; yy++)
+ {
+ for (zz=ext[4];zz<ext[5];zz++)
+ {
+ inside=actualCuttingModel->IfPointInside(xx,yy,zz);
+ if ( ((inside==true)&&(isinside==true)) || ((!inside==true)&&(!isinside)) )
+ {
+ value = *((unsigned short*)image->GetScalarPointer (xx,yy,zz));
+ pOrg=(unsigned short*)copyimage->GetScalarPointer (xx,yy,zz);
+ //std::cout<<"CutModelData::ExecuteUnCut() "<<value<<" "<<*pOrg<<std::endl;
+ *pOrg=(unsigned short)value;
+ } // if inside
+ } // for zz
+ } // for yy
+ } // for xx
+
+}
- double* pos = currentmatrix->GetPosition();
- modeltransform->Translate(pos[0]/spc[0],pos[1]/spc[1],pos[2]/spc[2]);
+vtkTransform* CutModelData::getModelTransform(vtkImageData* copyimage){
- double* scal = currentmatrix->GetScale();
- modeltransform->Scale(scal[0]/spc[0],scal[1]/spc[1],scal[2]/spc[2]);
+ double *spc = copyimage->GetSpacing();
+ modeltransform->Identity();
- /*matrixmodel->Identity();
+ vtkMatrix4x4* matrix = currentmatrix->GetMatrix();
+ vtkMatrix4x4* matrixmodel = modeltransform->GetMatrix();
matrixmodel->SetElement(0,0,matrix->GetElement(0,0)/spc[0]);
matrixmodel->SetElement(1,0,matrix->GetElement(1,0)/spc[0]);
matrixmodel->SetElement(2,0,matrix->GetElement(2,0)/spc[0]);
matrixmodel->SetElement(2,2,matrix->GetElement(2,2)/spc[2]);
matrixmodel->SetElement(0,3,matrix->GetElement(0,3)/spc[0]);
matrixmodel->SetElement(1,3,matrix->GetElement(1,3)/spc[1]);
- matrixmodel->SetElement(2,3,matrix->GetElement(2,3)/spc[2]);*/
+ matrixmodel->SetElement(2,3,matrix->GetElement(2,3)/spc[2]);
- //modeltransform->SetMatrix(matrixmodel);
+ /*
+
+ double* pos = currentmatrix->GetPosition();
+ modeltransform->Translate(pos[0]/spc[0],pos[1]/spc[1],pos[2]/spc[2]);
+ double* scal = currentmatrix->GetScale();
+ modeltransform->Scale(scal[0]/spc[0],scal[1]/spc[1],scal[2]/spc[2]);
+
+ //double* orient = currentmatrix->GetOrientation();
+ //modeltransform->RotateZ(orient[2]);
+ //modeltransform->RotateY(orient[1]);
+ //modeltransform->RotateX(orient[0]);
+ double* orient = currentmatrix->GetOrientationWXYZ();
+ modeltransform->RotateWXYZ(orient[0],orient[1],orient[2],orient[3]);
+
+ */
+
modeltransform->Update();
return modeltransform;
+}
+void CutModelData::setTransform(vtkTransform* transform, vtkImageData* img)throw( CutModelException){
+
+
+ double *spc = img->GetSpacing();
+
+ currentmatrix->Identity();
+
+ /*double* orient = transform->GetOrientationWXYZ();
+ currentmatrix->RotateWXYZ(orient[0],orient[1],orient[2],orient[3]);
+
+ double* pos = transform->GetPosition();
+ currentmatrix->Translate(pos[0]/spc[0],pos[1]/spc[1],pos[2]/spc[2]);
+
+ double* scal = transform->GetScale();
+ currentmatrix->Scale(scal[0]/spc[0],scal[1]/spc[1],scal[2]/spc[2]);
+
+ currentmatrix->Update(); */
+
+ _boxWidgetVolume->SetTransform(transform);
+
+ /*vtkMatrix4x4* matrix = transform->GetMatrix();
+ vtkMatrix4x4* matrixcurrent = currentmatrix->GetMatrix();
+ matrixcurrent->SetElement(0,0,matrix->GetElement(0,0)/spc[0]);
+ matrixcurrent->SetElement(1,0,matrix->GetElement(1,0)/spc[0]);
+ matrixcurrent->SetElement(2,0,matrix->GetElement(2,0)/spc[0]);
+ matrixcurrent->SetElement(0,1,matrix->GetElement(0,1)/spc[1]);
+ matrixcurrent->SetElement(1,1,matrix->GetElement(1,1)/spc[1]);
+ matrixcurrent->SetElement(2,1,matrix->GetElement(2,1)/spc[1]);
+ matrixcurrent->SetElement(0,2,matrix->GetElement(0,2)/spc[2]);
+ matrixcurrent->SetElement(1,2,matrix->GetElement(1,2)/spc[2]);
+ matrixcurrent->SetElement(2,2,matrix->GetElement(2,2)/spc[2]);
+ matrixcurrent->SetElement(0,3,matrix->GetElement(0,3)/spc[0]);
+ matrixcurrent->SetElement(1,3,matrix->GetElement(1,3)/spc[1]);
+ matrixcurrent->SetElement(2,3,matrix->GetElement(2,3)/spc[2]); */
+
+
+ udapteActorDirection();
+ getModelTransform(img);
+
}
vtkTransform* CutModelData::getModelTransformInvers(){
inversModel->Identity ();
inversModel->Concatenate ( modeltransform );
inversModel->Inverse();
return inversModel;
-}
\ No newline at end of file
+}
+
+vtkPolyData* CutModelData::getPolyData()throw( CutModelException){
+ return _Mapper->GetInput();
+}
+