<html>
<body>
John-<br><br>
I apologize if I've missed something here: for which classes are you
proposing these changes? vtkGlyph3D, vtkWarpScalar, and ?? How many
classes are involved? Your ideas have merit but I'm wondering if it
should be done class-by-class or somehow encapsulated in a helper
class...<br><br>
Will<br><br>
At 06:20 PM 5/11/2005, John Platt wrote:<br>
<blockquote type=cite class=cite cite=""><font face="arial" size=2>Hi,<br>
<br>
Maybe I’ve missed something but I seem to spend a lot of time modifying
filters to normalise the input data at the time of execution. Here’s an
example of bodging the scale factor so the warp is always shown a fixed
size.<br>
<br>
void vtkWarpScalarEx::Execute()<br>
{<br>
vtkDataArray* inScalars =
this->GetInput()->GetPointData()->GetScalars(
this->InputScalarsSelection );<br>
double scaleFactor = this->ScaleFactor;<br>
if ( inScalars )<br>
{<br>
double maxNorm =
inScalars->GetMaxNorm();<br>
if ( maxNorm > 0.0 )<br>
this->SetScaleFactor(
scaleFactor/maxNorm );<br>
}<br>
vtkWarpScalar::Execute();<br>
this->SetScaleFactor( scaleFactor );<br>
}<br>
<br>
Mapping attribute data to the range to [0,1] doesn’t always solve the
problem either, particularly when computing a scale factor for sizing
glyphs. For example, suppose there are sphere glyphs representing masses
M1 < M2 and M2 is to be displayed a fixed size. Normalising scalars
(say) to [0, 1] will leave M1 zero size. Provision for this kind of
functionality requires independent access to the attribute data limits.
Here is a solution for the mass problem using
UpperClampToMaxNormOn().<br>
<br>
vtkGlyph3D.h<br>
==========<br>
<br>
Replace <br>
<br>
// Description:<br>
// Specify range to map scalar values into.<br>
vtkSetVector2Macro(Range,double);<br>
vtkGetVectorMacro(Range,double,2);<br>
<br>
By<br>
<br>
// Description:<br>
// Specify the range for clamping the scalar values (or vector
magnitude if<br>
// ScaleByVector() is enabled). Scalars outside this range are set
to the<br>
// end points and then normalised to [0-1]. Glyphs for points with
scalars<br>
// less than or equal to Range[0] with therefore not be visible.
This range is<br>
// only used with ClampingOn()<br>
vtkSetVector2Macro(Range,double);<br>
vtkGetVectorMacro(Range,double,2);<br>
<br>
vtkSetMacro(LowerClampToMinNorm,int);<br>
vtkBooleanMacro(LowerClampToMinNorm,int);<br>
vtkGetMacro(LowerClampToMinNorm,int);<br>
<br>
vtkSetMacro(UpperClampToMaxNorm,int);<br>
vtkBooleanMacro(UpperClampToMaxNorm,int);<br>
vtkGetMacro(UpperClampToMaxNorm,int);<br>
<br>
Insert<br>
<br>
int LowerClampToMinNorm; // Use the min norm of the attribute data
as the lower clamp<br>
int UpperClampToMaxNorm; // Use the max norm of the attribute data
as the upper clamp<br>
<br>
<br>
vtkGlyph3D.cxx (Revision: 1.112)<br>
========================<br>
<br>
vtkGlyph3D::vtkGlyph3D()<br>
<br>
Insert<br>
<br>
this->LowerClampToMinNorm = 0;<br>
this->UpperClampToMaxNorm = 0;<br>
<br>
vtkGlyph3D::Execute()<br>
<br>
Remove<br>
<br>
// Check input for consistency<br>
//<br>
if ( (den = this->Range[1] - this->Range[0]) == 0.0 )<br>
{<br>
den = 1.0;<br>
}<br>
<br>
After <br>
<br>
else<br>
{<br>
haveVectors = 0;<br>
}<br>
<br>
Insert<br>
<br>
// Set the range for clamping the data scale factors.<br>
if ( this->Clamping && ( this->LowerClampToMinNorm
|| this->UpperClampToMaxNorm ) )<br>
{<br>
double* inRange = NULL;<br>
if ( inScalars && this->ScaleMode ==
VTK_SCALE_BY_SCALAR )<br>
{<br>
inRange = inScalars->GetRange();<br>
}<br>
else if ( haveVectors )<br>
{<br>
if ( this->VectorMode == VTK_USE_NORMAL
)<br>
{<br>
inRange =
inNormals->GetRange( -1 );<br>
}<br>
else<br>
{<br>
inRange =
inVectors->GetRange( -1 );<br>
}<br>
}<br>
if ( inRange && LowerClampToMinNorm )
this->Range[0] = inRange[0];<br>
if ( inRange && UpperClampToMaxNorm )
this->Range[1] = inRange[1];<br>
}<br>
<br>
if ( (den = this->Range[1] - this->Range[0]) == 0.0 ) den =
1.0;<br>
<br>
<br>
vtkGlyph3D::PrintSelf()<br>
<br>
Replace <br>
<br>
os << indent << "Range: (" <<
this->Range[0] << ", " << this->Range[1]
<< ")\n";<br>
<br>
By<br>
<br>
os << indent << "Range: (";<br>
this->LowerClampToMinNorm ? os << "Min
norm," : os << this->Range[0] <<
",";<br>
this->UpperClampToMaxNorm ? os << "Max norm)\n"
: os << this->Range[1] << ")\n";<br>
<br>
If this kind of functionality is useful I will add it to bug tracker as a
feature request.<br>
<br>
Where the clamping and normalisation are not combined, it would be useful
to have methods like<br>
<br>
ScaleByMinNorm()/ScaleByMaxNorm()<br>
SetLowerClamp( lower )/SetUpperClamp( upper )<br>
MapToRange( lower, upper )<br>
<br>
Using MapToRange( 0, 1 ) on vtkMapper would allow scalars of any range to
be colour mapped red through blue without having to call SetRange() with
actual attribute values. This would go some way to lessening the
assumption that the data range is known in advance.<br>
<br>
Thanks for your consideration.<br>
<br>
John Platt.<br>
<br>
</font>_______________________________________________<br>
vtk-developers mailing list<br>
vtk-developers@vtk.org<br>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers" eudora="autourl">
http://www.vtk.org/mailman/listinfo/vtk-developers</a></blockquote></body>
</html>