diff --git a/Modules/DiffusionImaging/DiffusionCore/include/Rendering/vtkOdfSource.h b/Modules/DiffusionImaging/DiffusionCore/include/Rendering/vtkOdfSource.h index 68acefff5e..9efec48bef 100644 --- a/Modules/DiffusionImaging/DiffusionCore/include/Rendering/vtkOdfSource.h +++ b/Modules/DiffusionImaging/DiffusionCore/include/Rendering/vtkOdfSource.h @@ -1,85 +1,85 @@ /*=================================================================== 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 __vtkOdfSource_h #define __vtkOdfSource_h #include #include "vtkPolyDataAlgorithm.h" #include "mitkCommon.h" #include #include #include class MITKDIFFUSIONCORE_EXPORT vtkOdfSource : public vtkPolyDataAlgorithm { public: vtkTypeMacro(vtkOdfSource,vtkPolyDataAlgorithm); void PrintSelf(ostream& os, vtkIndent indent) override; typedef itk::OrientationDistributionFunction OdfType; // Description: // Construct sphere with radius=0.5 and default resolution 8 in both Phi // and Theta directions. Theta ranges from (0,360) and phi (0,180) degrees. static vtkOdfSource *New(); vtkSetMacro(Scale,double); vtkGetMacro(Scale,double); vtkSetMacro(AdditionalScale,double); vtkGetMacro(AdditionalScale,double); vtkSetMacro(Normalization,int); vtkGetMacro(Normalization,int); vtkSetMacro(Odf,OdfType); vtkGetMacro(Odf,OdfType); vtkSetMacro(UseCustomColor,bool); vtkGetMacro(UseCustomColor,bool); void SetColor(int r, int g, int b) { this->r = r; this->g = g; this->b = b; } protected: vtkOdfSource(); - ~vtkOdfSource() {} + ~vtkOdfSource(); int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override; int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override; OdfType Odf; double Scale; double AdditionalScale; int Normalization; int r; int g; int b; bool UseCustomColor; vtkSmartPointer lut; private: vtkOdfSource(const vtkOdfSource&); // Not implemented. void operator=(const vtkOdfSource&); // Not implemented. }; #endif //__vtkOdfSource_h diff --git a/Modules/DiffusionImaging/DiffusionCore/src/Rendering/vtkOdfSource.cxx b/Modules/DiffusionImaging/DiffusionCore/src/Rendering/vtkOdfSource.cxx index 4967af38a2..06090b9156 100644 --- a/Modules/DiffusionImaging/DiffusionCore/src/Rendering/vtkOdfSource.cxx +++ b/Modules/DiffusionImaging/DiffusionCore/src/Rendering/vtkOdfSource.cxx @@ -1,127 +1,133 @@ #include "vtkOdfSource.h" #include "vtkCellArray.h" #include "vtkInformation.h" #include "vtkInformationVector.h" #include "vtkPoints.h" #include "vtkStreamingDemandDrivenPipeline.h" #include "vtkObjectFactory.h" #include "vtkDoubleArray.h" #include "vtkCellData.h" #include #include #include vtkStandardNewMacro(vtkOdfSource); vtkOdfSource::vtkOdfSource() : r(0) , g(0) , b(0) , UseCustomColor(false) { Scale = 1; lut = vtkLookupTable::New(); lut->SetRange(0,1); lut->Build(); this->SetNumberOfInputPorts(0); } +vtkOdfSource::~vtkOdfSource() +{ + lut->Delete(); +} + //---------------------------------------------------------------------------- int vtkOdfSource::RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector) { vtkPolyData* TemplateOdf = OdfType::GetBaseMesh(); // get the info object vtkInformation *outInfo = outputVector->GetInformationObject(0); // get the ouptut vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); OdfType colorOdf; switch(Normalization) { case mitk::ODFN_MINMAX: Odf = Odf.MinMaxNormalize(); colorOdf = Odf; break; case mitk::ODFN_MAX: Odf = Odf.MaxNormalize(); colorOdf = Odf; break; case mitk::ODFN_NONE: colorOdf = Odf.MaxNormalize(); break; default: Odf = Odf.MaxNormalize(); colorOdf = Odf; } vtkPoints *newPoints; vtkCellArray* polys = TemplateOdf->GetPolys(); output->SetPolys(polys); polys->InitTraversal(); newPoints = vtkPoints::New(); int numPoints = TemplateOdf->GetPoints()->GetNumberOfPoints(); newPoints->Allocate(numPoints); vtkSmartPointer point_colors = vtkSmartPointer::New(); point_colors->Allocate(output->GetNumberOfPoints() * 4); point_colors->SetNumberOfComponents(4); point_colors->SetName("ODF_COLORS"); unsigned char rgba[4]; double rgb[3]; for(int j=0; jGetPoints()->GetPoint(j,p); double val = Odf.GetElement(j); p[0] *= val*Scale*AdditionalScale*0.5; p[1] *= val*Scale*AdditionalScale*0.5; p[2] *= val*Scale*AdditionalScale*0.5; newPoints->InsertNextPoint(p); if (UseCustomColor) { rgba[0] = (unsigned char)r; rgba[1] = (unsigned char)g; rgba[2] = (unsigned char)b; } else { double color_val = colorOdf.GetElement(j); lut->GetColor(1-color_val, rgb); rgba[0] = (unsigned char)(255.0*rgb[0]); rgba[1] = (unsigned char)(255.0*rgb[1]); rgba[2] = (unsigned char)(255.0*rgb[2]); } rgba[3] = 255; point_colors->InsertTypedTuple(j, rgba); } output->SetPoints(newPoints); output->GetPointData()->AddArray(point_colors); newPoints->Delete(); + point_colors->Delete(); return 1; } //---------------------------------------------------------------------------- void vtkOdfSource::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); } //---------------------------------------------------------------------------- int vtkOdfSource::RequestInformation( vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector) { // get the info object vtkInformation *outInfo = outputVector->GetInformationObject(0); outInfo->Set(vtkAlgorithm::CAN_HANDLE_PIECE_REQUEST(),0); return 1; }