#include <vtkDataSet.h>
#include <vtkMath.h>
+static vtkFloatingPointType Tolerance = 1.0 / VTK_LARGE_FLOAT;
+
using namespace std;
vtkStandardNewMacro(VISU_FieldTransform);
-double VISU_FieldTransform::Ident(double theArg){
+double
+VISU_FieldTransform
+::Ident(double theArg)
+{
return theArg;
}
-double VISU_FieldTransform::Log10(double theArg){
- if(theArg <= 0.0) return -VTK_LARGE_FLOAT;
+
+double
+VISU_FieldTransform
+::Log10(double theArg)
+{
+ if(theArg <= 0.0)
+ return -VTK_LARGE_FLOAT;
+
return log10(theArg);
}
-VISU_FieldTransform::VISU_FieldTransform(){
+VISU_FieldTransform
+::VISU_FieldTransform()
+{
myFunction = &Ident;
myTransform = NULL;
+
+ myScalarRange[0] = VTK_LARGE_FLOAT;
+ myScalarRange[1] = -VTK_LARGE_FLOAT;
}
-VISU_FieldTransform::~VISU_FieldTransform() {
+VISU_FieldTransform
+::~VISU_FieldTransform()
+{
SetSpaceTransform(NULL);
}
-void VISU_FieldTransform::Update(){
- if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime())
- Modified();
+void
+VISU_FieldTransform
+::Update()
+{
vtkSource::Update();
}
-unsigned long VISU_FieldTransform::GetMTime(){
- if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime())
- return myTransform->GetMTime();
- return vtkSource::GetMTime();
+unsigned long
+VISU_FieldTransform
+::GetMTime()
+{
+ unsigned long aTime = Superclass::GetMTime();
+ if(myTransform)
+ aTime = max(aTime,myTransform->GetMTime());
+
+ return aTime;
}
-void VISU_FieldTransform::SetScalarTransform(TTransformFun theFunction) {
+void
+VISU_FieldTransform
+::SetScalarTransform(TTransformFun theFunction)
+{
+ if(myFunction == theFunction)
+ return;
+
+ if(theFunction == NULL)
+ theFunction = &Ident;
+
myFunction = theFunction;
- if(myFunction == NULL) myFunction = &Ident;
+
Modified();
}
void VISU_FieldTransform::SetSpaceTransform(VTKViewer_Transform* theTransform){
- if(myTransform != theTransform){
- if (myTransform != NULL) myTransform->UnRegister(this);
- myTransform = theTransform;
- if (myTransform != NULL) myTransform->Register(this);
- this->Modified();
- }
+ if(myTransform == theTransform)
+ return;
+
+ if(myTransform != NULL)
+ myTransform->UnRegister(this);
+
+ myTransform = theTransform;
+
+ if(theTransform != NULL)
+ theTransform->Register(this);
+
+ Modified();
}
-void VISU_FieldTransform::SetScalarRange(float theScalarRange[2]) {
+void
+VISU_FieldTransform
+::SetScalarRange(vtkFloatingPointType theScalarRange[2])
+{
+ vtkFloatingPointType aDelta =
+ fabs(myScalarRange[0] - theScalarRange[0]) +
+ fabs(myScalarRange[1] - theScalarRange[1]);
+ if(aDelta < Tolerance)
+ return;
+
myScalarRange[0] = theScalarRange[0];
myScalarRange[1] = theScalarRange[1];
+
Modified();
}
-void VISU_FieldTransform::SetScalarMin(float theValue){
- float aScalarRange[2] = {theValue, GetScalarRange()[1]};
+
+void
+VISU_FieldTransform
+::SetScalarMin(vtkFloatingPointType theValue)
+{
+ vtkFloatingPointType aScalarRange[2] = {theValue, GetScalarRange()[1]};
SetScalarRange(aScalarRange);
}
-void VISU_FieldTransform::SetScalarMax(float theValue){
- float aScalarRange[2] = {GetScalarRange()[0], theValue};
+
+void
+VISU_FieldTransform
+::SetScalarMax(vtkFloatingPointType theValue)
+{
+ vtkFloatingPointType aScalarRange[2] = {GetScalarRange()[0], theValue};
SetScalarRange(aScalarRange);
}
template<typename TypeData> void
ExecVectors(VISU_FieldTransform::TTransformFun theFunction,
VTKViewer_Transform* theTransform,
- float theScalarRange[2], int theNbComponent,
- TypeData* theInputData, TypeData* theOutputData)
+ vtkFloatingPointType theScalarRange[2],
+ int theNbOfTuples,
+ TypeData* theInputData,
+ TypeData* theOutputData)
{
- vtkDataArray *inVectors = theInputData->GetVectors();
- if ( !inVectors || theNbComponent < 1 ) return;
- vtkFloatArray *newVectors = vtkFloatArray::New();
- newVectors->SetNumberOfComponents(3);
- newVectors->SetNumberOfTuples(theNbComponent);
- float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])};
- float *V, v[3], vMag, aDelta = aScalarRange[1] - aScalarRange[0];
- float aScale[3] = {1.0, 1.0, 1.0};
+ vtkDataArray *anInVectors = theInputData->GetVectors();
+ if ( !anInVectors || theNbOfTuples < 1 )
+ return;
+ vtkFloatArray *aNewVectors = vtkFloatArray::New();
+ aNewVectors->SetNumberOfComponents(3);
+ aNewVectors->SetNumberOfTuples(theNbOfTuples);
+ vtkFloatingPointType aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])};
+ vtkFloatingPointType aDelta = aScalarRange[1] - aScalarRange[0];
+ vtkFloatingPointType aScale[3] = {1.0, 1.0, 1.0};
+ static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
if(theTransform){
aScale[0] = theTransform->GetScale()[0];
aScale[1] = theTransform->GetScale()[1];
aScale[2] = theTransform->GetScale()[2];
}
if(theFunction == &(VISU_FieldTransform::Ident)){
- for (int ptId = 0; ptId < theNbComponent; ptId++) {
- V = inVectors->GetTuple3(ptId);
- v[0] = V[0]*aScale[0];
- v[1] = V[1]*aScale[1];
- v[2] = V[2]*aScale[2];
- newVectors->SetTuple3(ptId, v[0], v[1], v[2]);
+ for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) {
+ vtkFloatingPointType anInVec[3];
+ anInVectors->GetTuple(aTupleId,anInVec);
+ vtkFloatingPointType anNewVec[3];
+ anNewVec[0] = anInVec[0]*aScale[0];
+ anNewVec[1] = anInVec[1]*aScale[1];
+ anNewVec[2] = anInVec[2]*aScale[2];
+ aNewVectors->SetTuple(aTupleId,anNewVec);
}
}else{
- for (int ptId = 0; ptId < theNbComponent; ptId++) {
- V = inVectors->GetTuple3(ptId);
- vMag = vtkMath::Norm(V);
- vMag = ((*theFunction)(vMag) - aScalarRange[0]) / aDelta * theScalarRange[1] / vMag;
- if(vMag <= 0.0) vMag = 0.0;
- v[0] = V[0]*vMag*aScale[0];
- v[1] = V[1]*vMag*aScale[1];
- v[2] = V[2]*vMag*aScale[2];
- newVectors->SetTuple3(ptId, v[0], v[1], v[2]);
+ for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) {
+ vtkFloatingPointType anInVec[3];
+ anInVectors->GetTuple(aTupleId,anInVec);
+ vtkFloatingPointType aMagn = vtkMath::Norm(anInVec);
+ if(aMagn > EPS)
+ aMagn = ((*theFunction)(aMagn) - aScalarRange[0]) / aDelta * theScalarRange[1] / aMagn;
+ if(aMagn < 0.0)
+ aMagn = 0.0;
+ vtkFloatingPointType anNewVec[3];
+ anNewVec[0] = anInVec[0]*aMagn*aScale[0];
+ anNewVec[1] = anInVec[1]*aMagn*aScale[1];
+ anNewVec[2] = anInVec[2]*aMagn*aScale[2];
+ aNewVectors->SetTuple(aTupleId,anNewVec);
}
}
- theOutputData->SetVectors(newVectors);
- newVectors->Delete();
+ theOutputData->SetVectors(aNewVectors);
+ aNewVectors->Delete();
}
template<typename TypeData> void
-ExecScalars(VISU_FieldTransform::TTransformFun theFunction, float theScalarRange[2],
- int theNbComponent, TypeData* theInputData, TypeData* theOutputData)
+ExecScalars(VISU_FieldTransform::TTransformFun theFunction,
+ vtkFloatingPointType theScalarRange[2],
+ int theNbOfTuples,
+ TypeData* theInputData,
+ TypeData* theOutputData)
{
- vtkDataArray *inScalars = theInputData->GetScalars();
- if ( !inScalars || theNbComponent < 1 )
+ vtkDataArray *anInScalars = theInputData->GetScalars();
+ if ( !anInScalars || theNbOfTuples < 1 )
return;
- vtkFloatArray *newScalars = vtkFloatArray::New();
- newScalars->SetNumberOfComponents(1);
- newScalars->SetNumberOfTuples(theNbComponent);
- float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])};
- for (int ptId = 0; ptId < theNbComponent; ptId++) {
- float s = (*theFunction)(inScalars->GetTuple1(ptId ));
- if(s < aScalarRange[0]) s = aScalarRange[0];
- newScalars->SetTuple1(ptId, s);
+ vtkFloatArray *aNewScalars = vtkFloatArray::New();
+ aNewScalars->SetNumberOfComponents(1);
+ aNewScalars->SetNumberOfTuples(theNbOfTuples);
+ vtkFloatingPointType aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])};
+ for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) {
+ vtkFloatingPointType aScalar = (*theFunction)(anInScalars->GetTuple1(aTupleId));
+ if(aScalar < aScalarRange[0])
+ aScalar = aScalarRange[0];
+ aNewScalars->SetTuple1(aTupleId,aScalar);
}
- theOutputData->SetScalars(newScalars);
- newScalars->Delete();
+ theOutputData->SetScalars(aNewScalars);
+ aNewScalars->Delete();
}
-void VISU_FieldTransform::Execute(){
+void
+VISU_FieldTransform
+::Execute()
+{
vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
output->CopyStructure(input);
if(myFunction != &Ident || (myTransform && !myTransform->IsIdentity())){