Salome HOME
Update Help for VISU module.
[modules/visu.git] / src / PIPELINE / VISU_FieldTransform.cxx
index ea239eb2f19f123330d43b39a5300b3648c4867f..5fd707425a202e69304563b7daa29b1e2a7ab698 100644 (file)
@@ -5,8 +5,8 @@
 //  File   : VISU_FieldTransform.cxx
 //  Module : VISU
 
-#include "VISU_FieldTransform.hxx"   
-#include "SALOME_Transform.h"
+#include "VISU_FieldTransform.hxx"
+#include "VTKViewer_Transform.h"
 
 #include <vtkObjectFactory.h>
 #include <vtkFloatArray.h>
 
 using namespace std;
 
-#ifdef DEBUG
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
 vtkStandardNewMacro(VISU_FieldTransform);
 
-double VISU_FieldTransform::Ident(double theArg){ 
+double VISU_FieldTransform::Ident(double theArg){
   return theArg;
 }
-double VISU_FieldTransform::Log10(double theArg){ 
+double VISU_FieldTransform::Log10(double theArg){
   if(theArg <= 0.0) return -VTK_LARGE_FLOAT;
   return log10(theArg);
 }
@@ -39,7 +33,9 @@ VISU_FieldTransform::VISU_FieldTransform(){
   myTransform = NULL;
 }
 
-VISU_FieldTransform::~VISU_FieldTransform() {}
+VISU_FieldTransform::~VISU_FieldTransform() {
+  SetSpaceTransform(NULL);
+}
 
 
 void VISU_FieldTransform::Update(){
@@ -54,13 +50,13 @@ unsigned long VISU_FieldTransform::GetMTime(){
   return vtkSource::GetMTime();
 }
 
-void VISU_FieldTransform::SetScalarTransform(TTransformFun theFunction) { 
+void VISU_FieldTransform::SetScalarTransform(TTransformFun theFunction) {
   myFunction = theFunction;
   if(myFunction == NULL) myFunction = &Ident;
   Modified();
 }
 
-void VISU_FieldTransform::SetSpaceTransform(SALOME_Transform* theTransform){
+void VISU_FieldTransform::SetSpaceTransform(VTKViewer_Transform* theTransform){
   if(myTransform != theTransform){
     if (myTransform != NULL) myTransform->UnRegister(this);
     myTransform = theTransform;
@@ -70,7 +66,7 @@ void VISU_FieldTransform::SetSpaceTransform(SALOME_Transform* theTransform){
 }
 
 
-void VISU_FieldTransform::SetScalarRange(float theScalarRange[2]) { 
+void VISU_FieldTransform::SetScalarRange(float theScalarRange[2]) {
   myScalarRange[0] = theScalarRange[0];
   myScalarRange[1] = theScalarRange[1];
   Modified();
@@ -84,14 +80,15 @@ void VISU_FieldTransform::SetScalarMax(float theValue){
   SetScalarRange(aScalarRange);
 }
 
+
 template<typename TypeData> void
-ExecVectors(VISU_FieldTransform::TTransformFun theFunction, 
-           SALOME_Transform* theTransform,
-           float theScalarRange[2], int theNbComponent, 
+ExecVectors(VISU_FieldTransform::TTransformFun theFunction,
+           VTKViewer_Transform* theTransform,
+           float theScalarRange[2], int theNbComponent,
            TypeData* theInputData, TypeData* theOutputData)
 {
   vtkDataArray *inVectors = theInputData->GetVectors();
-  if ( !inVectors || theNbComponent < 1 ) return; 
+  if ( !inVectors || theNbComponent < 1 ) return;
   vtkFloatArray *newVectors = vtkFloatArray::New();
   newVectors->SetNumberOfComponents(3);
   newVectors->SetNumberOfTuples(theNbComponent);
@@ -103,15 +100,25 @@ ExecVectors(VISU_FieldTransform::TTransformFun theFunction,
     aScale[1] = theTransform->GetScale()[1];
     aScale[2] = theTransform->GetScale()[2];
   }
-  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]);
+  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]);
+    }
+  }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]);
+    }
   }
   theOutputData->SetVectors(newVectors);
   newVectors->Delete();
@@ -122,8 +129,8 @@ ExecScalars(VISU_FieldTransform::TTransformFun theFunction, float theScalarRange
            int theNbComponent, TypeData* theInputData, TypeData* theOutputData)
 {
   vtkDataArray *inScalars = theInputData->GetScalars();
-  if ( !inScalars || theNbComponent < 1 ) 
-    return; 
+  if ( !inScalars || theNbComponent < 1 )
+    return;
   vtkFloatArray *newScalars = vtkFloatArray::New();
   newScalars->SetNumberOfComponents(1);
   newScalars->SetNumberOfTuples(theNbComponent);