[vtkusers] vtkImageGradient patch

Alexandre Guimond guimond at bwh.harvard.edu
Wed Jun 28 17:58:45 EDT 2000


Hi.  The doc for vtkImageGradient says: "OutputScalarType is always
float.".  This is not the case.  In the present CVS version,
the input and output need to the same type, ie if input is VTK_BIT,
output is VTK_BIT.  Here is a patch to make the code reflect what the
doc says.

I choose to change the code instead of the doc.  I think it makes more
sence to always have VTK_FLOAT for scalartype in gradient images.

Index: vtkImageGradient.cxx
===================================================================
RCS file: /vtk/cvsroot/vtk/imaging/vtkImageGradient.cxx,v
retrieving revision 1.29
diff -u -r1.29 vtkImageGradient.cxx
--- vtkImageGradient.cxx	2000/05/16 19:53:00	1.29
+++ vtkImageGradient.cxx	2000/06/28 18:03:47
@@ -102,6 +102,7 @@
 
   outData->SetWholeExtent(extent);
   outData->SetNumberOfScalarComponents(this->Dimensionality);
+  outData->SetScalarType(VTK_FLOAT);
 }
 
 
@@ -145,7 +146,7 @@
 template <class T>
 static void vtkImageGradientExecute(vtkImageGradient *self,
 				    vtkImageData *inData, T *inPtr,
-				    vtkImageData *outData, T *outPtr,
+				    vtkImageData *outData, float* outPtr,
 				    int outExt[6], int id)
 {
   int idxX, idxY, idxZ;
@@ -211,14 +212,14 @@
 	d = (float)(inPtr[useXMin]);
 	d -= (float)(inPtr[useXMax]);
 	d *= r[0]; // multiply by the data spacing
-	*outPtr = (T)(d);
+	*outPtr = (d);
 	outPtr++;
 	
 	// do y axis
 	d = (float)(inPtr[useYMin]);
 	d -= (float)(inPtr[useYMax]);
 	d *= r[1]; // multiply by the data spacing
-	*outPtr = (T)(d);
+	*outPtr = (d);
 	outPtr++;
 	if (axesNum == 3)
 	  {
@@ -226,7 +227,7 @@
 	  d = (float)(inPtr[useZMin]);
 	  d -= (float)(inPtr[useZMax]);
 	  d *= r[2]; // multiply by the data spacing
-	  *outPtr = (T)(d);
+	  *outPtr = (d);
 	  outPtr++;
 	  }
 	inPtr++;
@@ -249,16 +250,15 @@
 				       int outExt[6], int id)
 {
   void *inPtr = inData->GetScalarPointerForExtent(outExt);
-  void *outPtr = outData->GetScalarPointerForExtent(outExt);
+  float* outPtr = (float*)(outData->GetScalarPointerForExtent(outExt));
   
   vtkDebugMacro(<< "Execute: inData = " << inData 
 		<< ", outData = " << outData);
   
-  // this filter expects that input is the same type as output.
-  if (inData->GetScalarType() != outData->GetScalarType())
+  if (outData->GetScalarType() != VTK_FLOAT)
     {
-    vtkErrorMacro(<< "Execute: input ScalarType, " << inData->GetScalarType()
-    << ", must match out ScalarType " << outData->GetScalarType());
+    vtkErrorMacro(<< "Execute: output ScalarType, " << outData->GetScalarType()
+    << ", must be VTK_FLOAT");
     return;
     }
   
@@ -271,7 +271,7 @@
   switch (inData->GetScalarType())
     {
     vtkTemplateMacro7(vtkImageGradientExecute, this, inData, 
-                      (VTK_TT *)(inPtr), outData, (VTK_TT *)(outPtr), 
+                      (VTK_TT *)(inPtr), outData, outPtr, 
                       outExt, id);
     default:
       vtkErrorMacro(<< "Execute: Unknown ScalarType");

-- 
ag




More information about the vtkusers mailing list