[vtkusers] Scaling issue with vtkContourFilter

B.K. bastien.kovac at gmail.com
Wed May 18 11:12:27 EDT 2016


Hi everyone,

I'm having some issue with the display of quadric functions in VTK. I am
developping an application which gives me quadric equations corresponding to
an ellipsoid, and I would like to display them (Actually, I'm trying to
display the ellipsoids, vtkQuadric seemed like the easiest way since I
directly obtain the quadric's coefficients).

I'm working in Java, but I think I would be able to understand the logic
behind the code in C++ if that's more convenient to you.

Here is my code :

               / // This is where I store my coefficients
                Matrix q = quadric.getCoefficients();
		vtkQuadric quadricVTK = new vtkQuadric();
		double[] coeffs = q.getColumnPackedCopy();
		quadricVTK.SetCoefficients(coeffs[0], coeffs[1], coeffs[2], coeffs[3],
coeffs[4], coeffs[5], coeffs[6], coeffs[7], coeffs[8], coeffs[9]);

		vtkSampleFunction sample = new vtkSampleFunction();
		sample.SetImplicitFunction(quadricVTK);

		double[][] bounds = quadric.getBoundaries();
		double max = MathUtils.max(bounds[1]);

		sample.SetSampleDimensions(100, 100, 100);
		sample.SetModelBounds(-1.5 * max, 1.5 * max, -1.5 * max, 1.5 * max, -1.5 *
max, 1.5 * max);
		sample.ComputeNormalsOn();

		vtkContourFilter contourFilter = new vtkContourFilter();
		contourFilter.SetInputConnection(sample.GetOutputPort());
		contourFilter.SetValue(0, 0);
		contourFilter.Update();

		vtkPolyDataMapper mapper = new vtkPolyDataMapper();
		mapper.SetInputConnection(contourFilter.GetOutputPort());

		ellipsoidActor = new vtkActor();
		ellipsoidActor.SetMapper(mapper);
		// This is because scaling could change, its value during my test is
(1,1,1)
		ellipsoidActor.SetScale(ViewerUtil.getScale());/

Despite that, I keep ending up with very different results when I try to
plot the result with this code, and when I do it with MatLab (same values).
The overall shape seems good, but the size is completely different, you can
see it there, this is the result I obtain with the Java code (The points in
green are the points the ellipsoid should fit) :

<http://vtk.1045678.n5.nabble.com/file/n5738131/Ellipsoid.png> 

And, here is the ellipsoid displayed by MatLab with the same quadric
equation :

<http://vtk.1045678.n5.nabble.com/file/n5738131/Ellipsoid_matlab.png> 

Ugly, but it does the work (the points are the same as in the first
screenshot). Here is the code I use to display it in Matlab :

/// x is the matrix with the original points
s=1.5*max(abs(x(:)));

[X,Y,Z]=meshgrid(linspace(-s,s,100),linspace(-s,s,100),linspace(-s,s,100));

// Getting the quadric coefficients
q = Ellipsoid_Fitting_Centering(x, nit);

figure(1);plot3(x(1,:),x(2,:),x(3,:),'.');axis equal
hold on;
V=q(1)*X.^2+q(2)*Y.^2+q(3)*Z.^2+q(4)*X.*Y+q(5)*X.*Z+q(6)*Y.*Z+q(7)*X+q(8)*Y+q(9)*Z+q(10);
p=patch(isosurface(X,Y,Z,V,0));/


I'm starting to get really lost, I'm very new to VTK, and a lot of terms are
completely unknown to me, which doesn't help.

Thanks,
B.K.




--
View this message in context: http://vtk.1045678.n5.nabble.com/Scaling-issue-with-vtkContourFilter-tp5738131.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list