diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleTrackVisWriter.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleTrackVisWriter.cpp index 109ffc3480..362e3216f3 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleTrackVisWriter.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleTrackVisWriter.cpp @@ -1,104 +1,109 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkFiberBundleTrackVisWriter.h" #include #include #include #include #include #include #include #include #include #include #include "mitkDiffusionIOMimeTypes.h" mitk::FiberBundleTrackVisWriter::FiberBundleTrackVisWriter() : mitk::AbstractFileWriter(mitk::FiberBundle::GetStaticNameOfClass(), mitk::DiffusionIOMimeTypes::FIBERBUNDLE_TRK_MIMETYPE_NAME(), "TrackVis Fiber Bundle Reader") { - // Options defaultOptions; - // this->SetDefaultOptions(defaultOptions); + Options defaultOptions; + defaultOptions["Save in LPS space (if unchecked, use RAS)"] = true; + this->SetDefaultOptions(defaultOptions); + RegisterService(); } mitk::FiberBundleTrackVisWriter::FiberBundleTrackVisWriter(const mitk::FiberBundleTrackVisWriter & other) :mitk::AbstractFileWriter(other) {} mitk::FiberBundleTrackVisWriter::~FiberBundleTrackVisWriter() {} mitk::FiberBundleTrackVisWriter * mitk::FiberBundleTrackVisWriter::Clone() const { return new mitk::FiberBundleTrackVisWriter(*this); } void mitk::FiberBundleTrackVisWriter::Write() { std::ostream* out; std::ofstream outStream; if( this->GetOutputStream() ) { out = this->GetOutputStream(); }else{ outStream.open( this->GetOutputLocation().c_str() ); out = &outStream; } if ( !out->good() ) { mitkThrow() << "Stream not good."; } try { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); setlocale(LC_ALL, locale.c_str()); std::locale previousLocale(out->getloc()); std::locale I("C"); out->imbue(I); std::string filename = this->GetOutputLocation().c_str(); mitk::FiberBundle::ConstPointer input = dynamic_cast(this->GetInput()); std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation().c_str()); // default extension is .fib if(ext == "") { ext = ".trk"; this->SetOutputLocation(this->GetOutputLocation() + ext); } + Options options = this->GetOptions(); + bool lps = us::any_cast(options["Save in LPS space (if unchecked, use RAS)"]); + MITK_INFO << "Writing fiber bundle as TRK"; TrackVisFiberReader trk; - trk.create(filename, input.GetPointer()); + trk.create(filename, input.GetPointer(), lps); trk.writeHdr(); trk.append(input.GetPointer()); setlocale(LC_ALL, currLocale.c_str()); MITK_INFO << "Fiber bundle written"; } catch(...) { throw; } } diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkReader.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkReader.cpp index afee3da252..ee48fc1abb 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkReader.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkReader.cpp @@ -1,277 +1,277 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkFiberBundleVtkReader.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mitkDiffusionIOMimeTypes.h" mitk::FiberBundleVtkReader::FiberBundleVtkReader() : mitk::AbstractFileReader( mitk::DiffusionIOMimeTypes::FIBERBUNDLE_VTK_MIMETYPE_NAME(), "VTK Fiber Bundle Reader" ) { m_ServiceReg = this->RegisterService(); } mitk::FiberBundleVtkReader::FiberBundleVtkReader(const FiberBundleVtkReader &other) :mitk::AbstractFileReader(other) { } mitk::FiberBundleVtkReader * mitk::FiberBundleVtkReader::Clone() const { return new FiberBundleVtkReader(*this); } std::vector > mitk::FiberBundleVtkReader::Read() { std::vector > result; const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); setlocale(LC_ALL, locale.c_str()); std::string filename = this->GetInputLocation(); std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename); ext = itksys::SystemTools::LowerCase(ext); try { MITK_INFO << "Trying to load fiber file as VTK format."; vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName( this->GetInputLocation().c_str() ); if (reader->IsFilePolyData()) { reader->Update(); if ( reader->GetOutput() != NULL ) { vtkSmartPointer fiberPolyData = reader->GetOutput(); FiberBundle::Pointer fiberBundle = FiberBundle::New(fiberPolyData); vtkSmartPointer weights = vtkFloatArray::SafeDownCast(fiberPolyData->GetCellData()->GetArray("FIBER_WEIGHTS")); if (weights!=NULL) { - float weight=0; - for (int i=0; iGetSize(); i++) - if (!mitk::Equal(weights->GetValue(i),weight,0.00001)) - { - MITK_INFO << "Weight: " << weights->GetValue(i); - weight = weights->GetValue(i); - } +// float weight=0; +// for (int i=0; iGetSize(); i++) +// if (!mitk::Equal(weights->GetValue(i),weight,0.00001)) +// { +// MITK_INFO << "Weight: " << weights->GetValue(i); +// weight = weights->GetValue(i); +// } fiberBundle->SetFiberWeights(weights); } vtkSmartPointer fiberColors = vtkUnsignedCharArray::SafeDownCast(fiberPolyData->GetPointData()->GetArray("FIBER_COLORS")); if (fiberColors!=NULL) fiberBundle->SetFiberColors(fiberColors); result.push_back(fiberBundle.GetPointer()); return result; } } else MITK_INFO << "File is not VTK format."; } catch(...) { throw; } try { MITK_INFO << "Trying to load fiber file as VTP format."; vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName( this->GetInputLocation().c_str() ); if ( reader->CanReadFile(this->GetInputLocation().c_str()) ) { reader->Update(); if ( reader->GetOutput() != NULL ) { vtkSmartPointer fiberPolyData = reader->GetOutput(); FiberBundle::Pointer fiberBundle = FiberBundle::New(fiberPolyData); vtkSmartPointer weights = vtkFloatArray::SafeDownCast(fiberPolyData->GetCellData()->GetArray("FIBER_WEIGHTS")); if (weights!=NULL) { // float weight=0; // for (int i=0; iGetSize(); i++) // if (!mitk::Equal(weights->GetValue(i),weight,0.00001)) // { // MITK_INFO << "Weight: " << weights->GetValue(i); // weight = weights->GetValue(i); // } fiberBundle->SetFiberWeights(weights); } vtkSmartPointer fiberColors = vtkUnsignedCharArray::SafeDownCast(fiberPolyData->GetPointData()->GetArray("FIBER_COLORS")); if (fiberColors!=NULL) fiberBundle->SetFiberColors(fiberColors); result.push_back(fiberBundle.GetPointer()); return result; } } else MITK_INFO << "File is not VTP format."; } catch(...) { throw; } try { MITK_INFO << "Trying to load fiber file as deprecated XML format."; vtkSmartPointer fiberPolyData = vtkSmartPointer::New(); vtkSmartPointer cellArray = vtkSmartPointer::New(); vtkSmartPointer points = vtkSmartPointer::New(); TiXmlDocument doc( this->GetInputLocation().c_str() ); if(doc.LoadFile()) { TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); // save this for later hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChildElement("geometry").Element(); // read geometry mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); // read origin mitk::Point3D origin; double temp = 0; pElem->Attribute("origin_x", &temp); origin[0] = temp; pElem->Attribute("origin_y", &temp); origin[1] = temp; pElem->Attribute("origin_z", &temp); origin[2] = temp; geometry->SetOrigin(origin); // read spacing ScalarType spacing[3]; pElem->Attribute("spacing_x", &temp); spacing[0] = temp; pElem->Attribute("spacing_y", &temp); spacing[1] = temp; pElem->Attribute("spacing_z", &temp); spacing[2] = temp; geometry->SetSpacing(spacing); // read transform vtkMatrix4x4* m = vtkMatrix4x4::New(); pElem->Attribute("xx", &temp); m->SetElement(0,0,temp); pElem->Attribute("xy", &temp); m->SetElement(1,0,temp); pElem->Attribute("xz", &temp); m->SetElement(2,0,temp); pElem->Attribute("yx", &temp); m->SetElement(0,1,temp); pElem->Attribute("yy", &temp); m->SetElement(1,1,temp); pElem->Attribute("yz", &temp); m->SetElement(2,1,temp); pElem->Attribute("zx", &temp); m->SetElement(0,2,temp); pElem->Attribute("zy", &temp); m->SetElement(1,2,temp); pElem->Attribute("zz", &temp); m->SetElement(2,2,temp); m->SetElement(0,3,origin[0]); m->SetElement(1,3,origin[1]); m->SetElement(2,3,origin[2]); m->SetElement(3,3,1); geometry->SetIndexToWorldTransformByVtkMatrix(m); // read bounds float bounds[] = {0, 0, 0, 0, 0, 0}; pElem->Attribute("size_x", &temp); bounds[1] = temp; pElem->Attribute("size_y", &temp); bounds[3] = temp; pElem->Attribute("size_z", &temp); bounds[5] = temp; geometry->SetFloatBounds(bounds); geometry->SetImageGeometry(true); pElem = hRoot.FirstChildElement("fiber_bundle").FirstChild().Element(); for( ; pElem ; pElem=pElem->NextSiblingElement()) { TiXmlElement* pElem2 = pElem->FirstChildElement(); vtkSmartPointer container = vtkSmartPointer::New(); for( ; pElem2; pElem2=pElem2->NextSiblingElement()) { Point3D point; pElem2->Attribute("pos_x", &temp); point[0] = temp; pElem2->Attribute("pos_y", &temp); point[1] = temp; pElem2->Attribute("pos_z", &temp); point[2] = temp; geometry->IndexToWorld(point, point); vtkIdType id = points->InsertNextPoint(point.GetDataPointer()); container->GetPointIds()->InsertNextId(id); } cellArray->InsertNextCell(container); } fiberPolyData->SetPoints(points); fiberPolyData->SetLines(cellArray); vtkSmartPointer cleaner = vtkSmartPointer::New(); cleaner->SetInputData(fiberPolyData); cleaner->Update(); fiberPolyData = cleaner->GetOutput(); FiberBundle::Pointer image = FiberBundle::New(fiberPolyData); result.push_back(image.GetPointer()); return result; } else { MITK_INFO << "File is not deprectaed XML format."; } setlocale(LC_ALL, currLocale.c_str()); MITK_INFO << "Fiber bundle read"; } catch(...) { throw; } throw "Selected file is no vtk readable fiber format (binary or ascii vtk or vtp file)."; return result; } diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkWriter.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkWriter.cpp index aea343561a..b80a80fd72 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkWriter.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkFiberBundleVtkWriter.cpp @@ -1,155 +1,160 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkFiberBundleVtkWriter.h" #include #include #include #include #include #include #include #include #include #include #include #include "mitkDiffusionIOMimeTypes.h" mitk::FiberBundleVtkWriter::FiberBundleVtkWriter() : mitk::AbstractFileWriter(mitk::FiberBundle::GetStaticNameOfClass(), mitk::DiffusionIOMimeTypes::FIBERBUNDLE_VTK_MIMETYPE_NAME(), "VTK Fiber Bundle Writer") { Options defaultOptions; defaultOptions["Save as binary file"] = true; defaultOptions["Save as xml file (vtp style)"] = false; defaultOptions["Save color information"] = false; defaultOptions["Save fiber weights"] = true; this->SetDefaultOptions(defaultOptions); RegisterService(); } mitk::FiberBundleVtkWriter::FiberBundleVtkWriter(const mitk::FiberBundleVtkWriter & other) :mitk::AbstractFileWriter(other) {} mitk::FiberBundleVtkWriter::~FiberBundleVtkWriter() {} mitk::FiberBundleVtkWriter * mitk::FiberBundleVtkWriter::Clone() const { return new mitk::FiberBundleVtkWriter(*this); } void mitk::FiberBundleVtkWriter::Write() { std::ostream* out; std::ofstream outStream; if( this->GetOutputStream() ) { out = this->GetOutputStream(); }else{ outStream.open( this->GetOutputLocation().c_str() ); out = &outStream; } if ( !out->good() ) { mitkThrow() << "Stream not good."; } try { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); setlocale(LC_ALL, locale.c_str()); std::locale previousLocale(out->getloc()); std::locale I("C"); out->imbue(I); std::string filename = this->GetOutputLocation().c_str(); mitk::FiberBundle::ConstPointer input = dynamic_cast(this->GetInput()); std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation().c_str()); Options options = this->GetOptions(); vtkSmartPointer fibPoly = input->GetFiberPolyData(); if (us::any_cast(options["Save fiber weights"])) { MITK_INFO << "Adding fiber weight information"; fibPoly->GetCellData()->AddArray(input->GetFiberWeights()); } else if (fibPoly->GetCellData()->HasArray("FIBER_WEIGHTS")) fibPoly->GetCellData()->RemoveArray("FIBER_WEIGHTS"); if (us::any_cast(options["Save color information"])) { MITK_INFO << "Adding color information"; fibPoly->GetPointData()->AddArray(input->GetFiberColors()); } else if (fibPoly->GetPointData()->HasArray("FIBER_COLORS")) fibPoly->GetPointData()->RemoveArray("FIBER_COLORS"); + vtkSmartPointer mitk_flag = vtkSmartPointer::New(); + mitk_flag->SetName("SAVED_WITH_MITK"); + mitk_flag->InsertNextValue(true); + fibPoly->GetPointData()->AddArray(mitk_flag); + // default extension is .fib if(ext == "") { ext = ".fib"; this->SetOutputLocation(this->GetOutputLocation() + ext); } if (us::any_cast(options["Save as xml file (vtp style)"])) { vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetInputData(fibPoly); writer->SetFileName(filename.c_str()); if (us::any_cast(options["Save as binary file"])) { MITK_INFO << "Writing fiber bundle as vtk binary file"; writer->SetDataModeToBinary(); } else { MITK_INFO << "Writing fiber bundle as vtk ascii file"; writer->SetDataModeToAscii(); } writer->Write(); } else { vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetInputData(fibPoly); writer->SetFileName(filename.c_str()); if (us::any_cast(options["Save as binary file"])) { MITK_INFO << "Writing fiber bundle as vtk binary file"; writer->SetFileTypeToBinary(); } else { MITK_INFO << "Writing fiber bundle as vtk ascii file"; writer->SetFileTypeToASCII(); } writer->Write(); } setlocale(LC_ALL, currLocale.c_str()); MITK_INFO << "Fiber bundle written"; } catch(...) { throw; } } diff --git a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.cpp b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.cpp index 3f43b32d48..e501575e58 100644 --- a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.cpp +++ b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.cpp @@ -1,237 +1,240 @@ #include #include TrackVisFiberReader::TrackVisFiberReader() { m_Filename = ""; m_FilePointer = nullptr; } TrackVisFiberReader::~TrackVisFiberReader() { if (m_FilePointer) fclose( m_FilePointer ); } // Create a TrackVis file and store standard metadata. The file is ready to append fibers. // --------------------------------------------------------------------------------------- -short TrackVisFiberReader::create(string filename , const mitk::FiberBundle *fib) +short TrackVisFiberReader::create(string filename , const mitk::FiberBundle *fib, bool lps) { // prepare the header for(int i=0; i<3 ;i++) { if (fib->GetReferenceGeometry().IsNotNull()) { m_Header.dim[i] = fib->GetReferenceGeometry()->GetExtent(i); m_Header.voxel_size[i] = fib->GetReferenceGeometry()->GetSpacing()[i]; m_Header.origin[i] = fib->GetReferenceGeometry()->GetOrigin()[i]; } else { m_Header.dim[i] = fib->GetGeometry()->GetExtent(i); m_Header.voxel_size[i] = fib->GetGeometry()->GetSpacing()[i]; m_Header.origin[i] = fib->GetGeometry()->GetOrigin()[i]; } } m_Header.n_scalars = 0; m_Header.n_properties = 0; - sprintf(m_Header.voxel_order,"LPS"); + if (lps) + sprintf(m_Header.voxel_order,"LPS"); + else + sprintf(m_Header.voxel_order,"RAS"); m_Header.image_orientation_patient[0] = 1.0; m_Header.image_orientation_patient[1] = 0.0; m_Header.image_orientation_patient[2] = 0.0; m_Header.image_orientation_patient[3] = 0.0; m_Header.image_orientation_patient[4] = 1.0; m_Header.image_orientation_patient[5] = 0.0; m_Header.pad1[0] = 0; m_Header.pad1[1] = 0; m_Header.pad2[0] = 0; m_Header.pad2[1] = 0; m_Header.invert_x = 0; m_Header.invert_y = 0; m_Header.invert_z = 0; m_Header.swap_xy = 0; m_Header.swap_yz = 0; m_Header.swap_zx = 0; m_Header.n_count = 0; m_Header.version = 1; m_Header.hdr_size = 1000; // write the header to the file m_FilePointer = fopen(filename.c_str(),"w+b"); if (m_FilePointer == nullptr) { printf("[ERROR] Unable to create file '%s'\n",filename.c_str()); return 0; } sprintf(m_Header.id_string,"TRACK"); if (fwrite((char*)&m_Header, 1, 1000, m_FilePointer) != 1000) MITK_ERROR << "TrackVis::create : Error occurding during writing fiber."; this->m_Filename = filename; return 1; } // Open an existing TrackVis file and read metadata information. // The file pointer is positiond at the beginning of fibers data // ------------------------------------------------------------- short TrackVisFiberReader::open( string filename ) { m_FilePointer = fopen(filename.c_str(), "rb"); if (m_FilePointer == nullptr) { printf("[ERROR] Unable to open file '%s'\n",filename.c_str()); return 0; } this->m_Filename = filename; return fread((char*)(&m_Header), 1, 1000, m_FilePointer); } // Append a fiber to the file // -------------------------- short TrackVisFiberReader::append(const mitk::FiberBundle *fib) { vtkPolyData* poly = fib->GetFiberPolyData(); for (int i=0; iGetNumFibers(); i++) { vtkCell* cell = poly->GetCell(i); int numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); unsigned int numSaved, pos = 0; //float* tmp = new float[3*maxSteps]; std::vector< float > tmp; tmp.reserve(3*numPoints); numSaved = numPoints; for(unsigned int i=0; iGetPoint(i); tmp[pos++] = p[0]; tmp[pos++] = p[1]; tmp[pos++] = p[2]; } // write the coordinates to the file if ( fwrite((char*)&numSaved, 1, 4, m_FilePointer) != 4 ) { printf( "[ERROR] Problems saving the fiber!\n" ); return 1; } if ( fwrite((char*)&(tmp.front()), 1, 4*pos, m_FilePointer) != 4*pos ) { printf( "[ERROR] Problems saving the fiber!\n" ); return 1; } } return 0; } //// Read one fiber from the file //// ---------------------------- short TrackVisFiberReader::read( mitk::FiberBundle* fib ) { int numPoints; vtkSmartPointer vtkNewPoints = vtkSmartPointer::New(); vtkSmartPointer vtkNewCells = vtkSmartPointer::New(); while (fread((char*)&numPoints, 1, 4, m_FilePointer)==4) { if ( numPoints <= 0 ) { printf( "[ERROR] Trying to read a fiber with %d points!\n", numPoints ); return -1; } vtkSmartPointer container = vtkSmartPointer::New(); float tmp[3]; for(int i=0; iInsertNextPoint(tmp); container->GetPointIds()->InsertNextId(id); } vtkNewCells->InsertNextCell(container); } vtkSmartPointer fiberPolyData = vtkSmartPointer::New(); fiberPolyData->SetPoints(vtkNewPoints); fiberPolyData->SetLines(vtkNewCells); MITK_INFO << "Coordinate convention: " << m_Header.voxel_order; mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); vtkSmartPointer< vtkMatrix4x4 > matrix = vtkSmartPointer< vtkMatrix4x4 >::New(); matrix->Identity(); if (m_Header.voxel_order[0]=='R') matrix->SetElement(0,0,-matrix->GetElement(0,0)); if (m_Header.voxel_order[1]=='A') matrix->SetElement(1,1,-matrix->GetElement(1,1)); if (m_Header.voxel_order[2]=='I') matrix->SetElement(2,2,-matrix->GetElement(2,2)); geometry->SetIndexToWorldTransformByVtkMatrix(matrix); vtkSmartPointer transformFilter = vtkSmartPointer::New(); transformFilter->SetInputData(fiberPolyData); transformFilter->SetTransform(geometry->GetVtkTransform()); transformFilter->Update(); fib->SetFiberPolyData(transformFilter->GetOutput()); mitk::Point3D origin; origin[0]=m_Header.origin[0]; origin[1]=m_Header.origin[1]; origin[2]=m_Header.origin[2]; geometry->SetOrigin(origin); mitk::Vector3D spacing; spacing[0]=m_Header.voxel_size[0]; spacing[1]=m_Header.voxel_size[1]; spacing[2]=m_Header.voxel_size[2]; geometry->SetSpacing(spacing); geometry->SetExtentInMM(0, m_Header.voxel_size[0]*m_Header.dim[0]); geometry->SetExtentInMM(1, m_Header.voxel_size[1]*m_Header.dim[1]); geometry->SetExtentInMM(2, m_Header.voxel_size[2]*m_Header.dim[2]); fib->SetReferenceGeometry(dynamic_cast(geometry.GetPointer())); return numPoints; } // Update the field in the header to the new FIBER TOTAL. // ------------------------------------------------------ void TrackVisFiberReader::updateTotal( int totFibers ) { fseek(m_FilePointer, 1000-12, SEEK_SET); if (fwrite((char*)&totFibers, 1, 4, m_FilePointer) != 4) MITK_ERROR << "[ERROR] Problems saving the fiber!"; } void TrackVisFiberReader::writeHdr() { fseek(m_FilePointer, 0, SEEK_SET); if (fwrite((char*)&m_Header, 1, 1000, m_FilePointer) != 1000) MITK_ERROR << "[ERROR] Problems saving the fiber!"; } // Close the TrackVis file, but keep the metadata in the header. // ------------------------------------------------------------- void TrackVisFiberReader::close() { fclose(m_FilePointer); m_FilePointer = nullptr; } bool TrackVisFiberReader::IsTransformValid() { if (fabs(m_Header.image_orientation_patient[0])<=0.001 || fabs(m_Header.image_orientation_patient[3])<=0.001 || fabs(m_Header.image_orientation_patient[5])<=0.001) return false; return true; } diff --git a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.h b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.h index 2d151f3313..ee931b73df 100644 --- a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.h +++ b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundle/mitkTrackvis.h @@ -1,82 +1,82 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _TRACKVIS #define _TRACKVIS #include #include #include #include #include #include #include #include using namespace std; // Structure to hold metadata of a TrackVis file // --------------------------------------------- struct TrackVis_header { char id_string[6]; short int dim[3]; float voxel_size[3]; float origin[3]; short int n_scalars; char scalar_name[10][20]; short int n_properties; char property_name[10][20]; char reserved[508]; char voxel_order[4]; char pad2[4]; float image_orientation_patient[6]; char pad1[2]; unsigned char invert_x; unsigned char invert_y; unsigned char invert_z; unsigned char swap_xy; unsigned char swap_yz; unsigned char swap_zx; int n_count; int version; int hdr_size; }; // Class to handle TrackVis files. // ------------------------------- class MITKFIBERTRACKING_EXPORT TrackVisFiberReader { private: string m_Filename; FILE* m_FilePointer; public: TrackVis_header m_Header; - short create(string m_Filename, const mitk::FiberBundle* fib); + short create(string m_Filename, const mitk::FiberBundle* fib, bool lps); short open( string m_Filename ); short read( mitk::FiberBundle* fib ); short append(const mitk::FiberBundle* fib ); void writeHdr(); void updateTotal( int totFibers ); void close(); bool IsTransformValid(); TrackVisFiberReader(); ~TrackVisFiberReader(); }; #endif