CutModelSaveBinInfo.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   wxMaracas
00004   Module:    $RCSfile: CutModelSaveBinInfo.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2009/10/16 15:17:56 $
00007   Version:   $Revision: 1.2 $
00008 
00009   Copyright: (c) 2002, 2003
00010   License:
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notice for more information.
00015 
00016 =========================================================================*/
00017 #include "CutModelSaveBinInfo.h"
00018 
00022 CutModelSaveBinInfo::CutModelSaveBinInfo(int id, int currentaction, UNDOTYPE actiontype, std::string path){
00023 
00024         _id = id;
00025 
00026         char c[100];
00027         sprintf(c,"/infounrd_%d_fig_%d.info",currentaction,id);
00028 
00029         _stdFilename = path;    
00030     _stdFilename+=c;
00031         _stdFilename+=".poly";
00032 
00033         _matrixFilename = path; 
00034         _matrixFilename+=c;
00035         _actiontype = actiontype;       
00036 
00037         
00038 }
00039 CutModelSaveBinInfo::~CutModelSaveBinInfo(){
00040         
00041 }
00042 void CutModelSaveBinInfo::savePolyData(vtkPolyData* polydata){
00043         vtkPolyDataWriter * writer = vtkPolyDataWriter ::New();
00044         writer->SetFileName(_stdFilename.c_str());      
00045         writer->SetInput(polydata);
00046         writer->SetFileTypeToBinary();
00047         writer->Write();
00048         writer->Delete();
00049 }
00050 
00051 vtkTransform* CutModelSaveBinInfo::getPolyDataTransform()throw( CutModelException){
00052         vtkPolyDataReader* reader = vtkPolyDataReader::New();
00053         //std::cout<<"filename vtkTransform* CutModelSaveBinInfo::getPolyDataTransform()"<<this->getSTDFileName()<<std::endl;
00054         reader->SetFileName(this->getSTDFileName().c_str());
00055         vtkPolyData* poly = reader->GetOutput();
00056 
00057         vtkPolyDataMapper* mapper       = vtkPolyDataMapper::New();     
00058         mapper->SetInput(poly);
00059         vtkActor* actor = vtkActor::New();
00060         actor->SetMapper(mapper);
00061         vtkMatrix4x4* actmatrix = actor->GetMatrix();
00062 
00063         std::cout<<"tkTransform* CutModelSaveBinInfo::getPolyDataTransform() Actor "<<actor<<std::endl;
00064         std::cout<<"tkTransform* CutModelSaveBinInfo::getPolyDataTransform() Actor Matrix "<<actmatrix<<std::endl;
00065 
00066         mapper->Update();
00067 
00068         vtkTransform* transform = vtkTransform::New();
00069 
00070         transform->Identity();
00071 
00072         transform->GetMatrix()->SetElement(0,0,actmatrix->GetElement(0,0));
00073         transform->GetMatrix()->SetElement(1,0,actmatrix->GetElement(1,0));
00074         transform->GetMatrix()->SetElement(2,0,actmatrix->GetElement(2,0));
00075         transform->GetMatrix()->SetElement(0,1,actmatrix->GetElement(0,1));
00076         transform->GetMatrix()->SetElement(1,1,actmatrix->GetElement(1,1));
00077         transform->GetMatrix()->SetElement(2,1,actmatrix->GetElement(2,1));
00078         transform->GetMatrix()->SetElement(0,2,actmatrix->GetElement(0,2));
00079         transform->GetMatrix()->SetElement(1,2,actmatrix->GetElement(1,2));
00080         transform->GetMatrix()->SetElement(2,2,actmatrix->GetElement(2,2));             
00081         transform->GetMatrix()->SetElement(0,3,actmatrix->GetElement(0,3));
00082         transform->GetMatrix()->SetElement(1,3,actmatrix->GetElement(1,3));
00083         transform->GetMatrix()->SetElement(2,3,actmatrix->GetElement(2,3));
00084 
00085         actor->Delete();
00086         mapper->Delete();
00087         reader->Delete();
00088         //poly->Delete();
00089         
00090 
00091         return transform;
00092         
00093 }
00094 
00095 
00096 void CutModelSaveBinInfo::saveMatrix4x4(vtkMatrix4x4* matrix){
00097         fstream binary_file(_matrixFilename.c_str(),ios::out|ios::binary);
00098         binary_file.write(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
00099         binary_file.close();
00100 }
00101 vtkTransform* CutModelSaveBinInfo::getTransformFromMatrixFile()throw( CutModelException){
00102         vtkMatrix4x4* matrix = vtkMatrix4x4::New();
00103         fstream binary_file(_matrixFilename.c_str(),ios::binary|ios::in);
00104         binary_file.read(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
00105         binary_file.close();
00106 
00107         vtkTransform* transform = vtkTransform::New();
00108         transform->SetMatrix(matrix);
00109 
00110         return transform;
00111 }
00112 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1