X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FcreaVtk.txx;h=c4e7167747d135f05c2d48269e4b445efb39bc82;hb=aea7a7a670afd36baafabc8f924902551f852006;hp=bbebc1dad8e79fe1702f3559ff6d3b4847e21e37;hpb=7c20ef5b6b9bcfe07f7b8e887360b70fc399962c;p=crea.git diff --git a/src/creaVtk.txx b/src/creaVtk.txx index bbebc1d..c4e7167 100644 --- a/src/creaVtk.txx +++ b/src/creaVtk.txx @@ -16,22 +16,26 @@ #include #include namespace crea -{ - +{ template - vtkImageData* CREA_EXPORT NewVtkImageDataFromRaw( T* data, + /*CREA_EXPORT*/ vtkImageData* NewVtkImageDataFromRaw( T* data, int nx, int ny, - int nz) + int nz, + bool do_not_desalloc) { // std::cout << "NV "<::SizedName() << std::endl; - vtkImageData *image = vtkImageData::New(); + vtkImageData *image = vtkImageData::New(); + + // Shouldn't we pass NumberOfScalarComponents to deal with RGB, RGBA images as well? // JPR + image->SetNumberOfScalarComponents(1); + int vtktype = vtkTypeTraits::VTKTypeID(); image->SetScalarType(vtktype); - image->SetDimensions(nx,ny,nz); - image->SetSpacing(1,1,1); + image->SetDimensions(nx, ny ,nz); + image->SetSpacing(1, 1, 1); image->AllocateScalars(); vtkDataArray* array = 0; switch (vtktype) @@ -64,11 +68,15 @@ namespace crea <<" non implemented"); } vtkDataArrayTemplate* tarray - = dynamic_cast*>(array); + = dynamic_cast*>(array); array->SetNumberOfComponents( 1 ); size_t size = (long)nx*(long)ny*(long)nz; - // The last param of SetArray is set to 1 to keep the class from deleting the array when it cleans up or reallocates memory. - tarray->SetArray( data, size, 1 ); + // The last param of SetArray is set to 1 to keep the class from deleting the array + // when it cleans up or reallocates memory. + int dndesa = 0; + if (do_not_desalloc) + dndesa = 1; + tarray->SetArray( data, size, dndesa ); image->GetPointData( )->SetScalars( tarray ); array->Delete( ); return image;