[med-svn] [SCM] mia branch, master, updated. upstream/2.0.9-76-g552bd78
Gert Wollny
gw.fossdev at gmail.com
Fri Apr 26 15:01:49 UTC 2013
The following commit has been merged in the master branch:
commit 552bd78bafebb57373e6f22c700e59c40d3cc3bf
Author: Gert Wollny <gw.fossdev at gmail.com>
Date: Fri Apr 26 14:09:11 2013 +0200
actually apply the patches
diff --git a/addons/vtk/vtkvf.cc b/addons/vtk/vtkvf.cc
index 4fd9218..cd5d402 100644
--- a/addons/vtk/vtkvf.cc
+++ b/addons/vtk/vtkvf.cc
@@ -20,9 +20,9 @@
#include <vtk/vtkvf.hh>
-#include <vtkStructuredGridReader.h>
-#include <vtkStructuredGridWriter.h>
-#include <vtkStructuredGrid.h>
+#include <vtkStructuredPointsReader.h>
+#include <vtkStructuredPointsWriter.h>
+#include <vtkStructuredPoints.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
@@ -41,9 +41,25 @@ CVtk3DVFIOPlugin::CVtk3DVFIOPlugin():
}
+
+template <typename T>
+C3DIOVectorfield *read_field_data(const C3DBounds& size, void *scalars)
+{
+ cvdebug() << "VTKVF read vector data of type " << __type_descr<T>::value << "\n";
+
+ const T *my_scalars = reinterpret_cast<const T *>(scalars);
+ if (!my_scalars)
+ throw create_exception<logic_error>("CVtk3DImageIOPlugin::load: input image scalar type bogus");
+
+ C3DIOVectorfield *result = new C3DIOVectorfield(size);
+ copy(my_scalars, my_scalars + 3 * result->size(), &(*result)[0].x);
+
+ return result;
+}
+
CVtk3DVFIOPlugin::PData CVtk3DVFIOPlugin::do_load(const string& filename) const
{
- auto reader = vtkSmartPointer<vtkStructuredGridReader>::New();
+ auto reader = vtkSmartPointer<vtkStructuredPointsReader>::New();
reader->SetFileName(filename.c_str());
auto iovf = reader->GetOutput();
iovf->Update();
@@ -57,54 +73,51 @@ CVtk3DVFIOPlugin::PData CVtk3DVFIOPlugin::do_load(const string& filename) const
}
auto dims = iovf->GetDimensions();
+ if (dim != 3)
+ throw create_exception<invalid_argument>("3D Vtkvf load (", filename ,
+ "): Expect 3 dimensions but got ", dim);
C3DBounds size(dims[0], dims[1], dims[2]);
+
+ int components = iovf->GetNumberOfScalarComponents();
+ if (components != 3)
+ throw create_exception<invalid_argument>("3D Vtkvf load (", filename ,
+ "): only 3D vectors are allowed, "
+ "but got ", components, " component elements");
+
- PData result(new C3DIOVectorfield(size));
-
- auto points = iovf->GetPoints();
-
-
- if (points->GetNumberOfPoints() != size.product())
- throw create_exception<invalid_argument>("Got ", points->GetNumberOfPoints(),
- " vectors but require ", size.product());
- vtkIdType i = 0;
- for (auto iv = result->begin(); iv != result->end(); ++iv, ++i) {
- double x[3];
- points->GetPoint (i, x);
- iv->x = x[0];
- iv->y = x[1];
- iv->z = x[2];
+ auto array = iovf->GetScalarPointer();
+
+ C3DIOVectorfield *result_field = nullptr;
+ switch (iovf->GetScalarType()) {
+ case VTK_FLOAT: result_field=read_field_data<float>(size, array); break;
+ case VTK_DOUBLE: result_field=read_field_data<double>(size, array); break;
+ default:
+ throw create_exception<invalid_argument>("3D Vtkvf load (", filename ,"): "
+ "data type ", iovf->GetScalarTypeAsString(),
+ "(", iovf->GetScalarType(), ") not supported");
}
- return result;
+ return PData(result_field);
}
bool CVtk3DVFIOPlugin::do_save(const string& fname, const C3DIOVectorfield& data) const
{
- int dims[3];
- dims[0] = data.get_size().x;
- dims[1] = data.get_size().y;
- dims[2] = data.get_size().z;
-
- auto sgrid = vtkSmartPointer<vtkStructuredGrid>::New();
- sgrid->SetDimensions(dims);
-
- auto points = vtkSmartPointer<vtkPoints>::New();
- points->Allocate(data.get_size().product());
-
- int offset = 0;
- float v[3];
- for (auto iv = data.begin(); iv != data.end(); ++iv, ++offset) {
- v[0] = iv->x;
- v[1] = iv->y;
- v[2] = iv->z;
- points->InsertPoint(offset, v);
- }
- sgrid->SetPoints(points);
+
+ auto outfield = vtkSmartPointer<vtkStructuredPoints>::New();
+ outfield->SetOrigin(0,0,0);
+ outfield->SetSpacing(1.0, 1.0, 1.0);
+ outfield->SetDimensions(data.get_size().x, data.get_size().y, data.get_size().z);
+
+ outfield->SetScalarType(VTK_FLOAT);
+ outfield->SetNumberOfScalarComponents(3);
+ outfield->AllocateScalars();
+
+ float *out_ptr = reinterpret_cast<float*>(outfield->GetScalarPointer());
+ copy(&data[0].x, &data[0].x + data.size() * 3, out_ptr);
- auto writer = vtkSmartPointer<vtkStructuredGridWriter>::New();
+ auto writer = vtkSmartPointer<vtkStructuredPointsWriter>::New();
writer->SetFileName(fname.c_str());
writer->SetFileTypeToBinary();
- writer->SetInput(sgrid);
+ writer->SetInput(outfield);
return writer->Write();
}
diff --git a/mia/3d/filter/scale.cc b/mia/3d/filter/scale.cc
index a1180cb..6d0fe58 100644
--- a/mia/3d/filter/scale.cc
+++ b/mia/3d/filter/scale.cc
@@ -137,6 +137,8 @@ C3DScaleFilterPlugin::C3DScaleFilterPlugin():
C3DFilterPlugin("scale"),
m_s(0,0,0)
{
+ add_parameter("s", new C3DBoundsParameter(m_s, 0,"target size to set all components at once (component 0:use input image size)"));
+
add_parameter("sx", new CUIntParameter(m_s.x, 0,
numeric_limits<unsigned int>::max(), false,
"target size in x direction (0:use input image size)"));
--
Packaging of mia in Debian
More information about the debian-med-commit
mailing list