From ab91e25f4ca81c10788da1fdd681a87f1f17641e Mon Sep 17 00:00:00 2001
From: Eduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Date: Mon, 26 Apr 2021 09:00:02 +0200
Subject: [PATCH] #3459 Bug Refresh LookupTable SurfaceTexture

---
 packages/std/src/bbstdMathOperationVector.h |  2 +-
 packages/vtk/src/bbvtkPolyDataToActor.cxx   |  2 +-
 packages/vtk/src/bbvtkSurfaceTexture.cxx    | 16 +++++++++++++---
 packages/vtk/src/bbvtkSurfaceTexture.h      |  2 +-
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/packages/std/src/bbstdMathOperationVector.h b/packages/std/src/bbstdMathOperationVector.h
index fe00fbc..9451161 100644
--- a/packages/std/src/bbstdMathOperationVector.h
+++ b/packages/std/src/bbstdMathOperationVector.h
@@ -63,7 +63,7 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(MathOperationVector,bbtk::AtomicBlackBox);
   BBTK_INPUT(MathOperationVector,In7,"Input vector 7",std::vector<double>,"");
   BBTK_INPUT(MathOperationVector,In8,"Input vector 8",std::vector<double>,"");
   BBTK_INPUT(MathOperationVector,In9,"Input vector 9",std::vector<double>,"");
-  BBTK_INPUT(MathOperationVector,Type,"Type (defalult 0): 0  adition (default) In0[i]+In1[i]+..+In9[i], -99 adition In0[i] In1[i] ... In[9], 1 sustraction In0[i]-In1[i]-..-In9[i], 2 multiplication In0[i]*In2[i]*...*In9[i], 3 division In0/In1/.../In9, 4 sqrt In1, 5 log10 In1, 6 exp In1, 7 incremental int [In0..In1], 8 random int [In0..In1], 9 (rad) sin In0, 10 (rad) cos In0, 11 tan (rad) In0, 12 asin In0, 13 acos In0, 14 atan In0, 15 atan2 In0 In1 , 16 min (In0[i],In1[i]..In9[i]), -16 min(In0) min(In1) ... min(In9) , 17 max (In0[i],In1[i]..In9[i]), -17 max(In0) max(In1) ... max(In9) , 18 abs In0 , 19 module In0[i]%In1[i] , 20 lessThan In0[i]<In1[i], 21 greaterThan In0[i]>In1[i], 22 Centre of Mass In0=lstX In1=lstY In2=lstZ In3=lstValues " ,int,"");
+  BBTK_INPUT(MathOperationVector,Type,"Type (defalult 0): 0  adition (default) In0[i]+In1[i]+..+In9[i], -99 adition In0[i] In1[i] ... In[9], 1 sustraction In0[i]-In1[i]-..-In9[i], 2 multiplication In0[i]*In2[i]*...*In9[i], 3 division In0/In1/.../In9, 4 sqrt In1, 5 log10 In1, 6 exp In1, 7 incremental int [In0..In1], 8 random int [In0..In1], 9 (rad) sin In0, 10 (rad) cos In0, 11 tan (rad) In0, 12 asin In0, 13 acos In0, 14 atan In0, 15 atan2 In0 In1 , 16 min (In0[i],In1[i]..In9[i]), -16 min(In0) min(In1) ... min(In9) , 17 max (In0[i],In1[i]..In9[i]), -17 max(In0) max(In1) ... max(In9) , 18 abs In0 , 19 module In0[i]%In1[i] , 20 lessThan In0[i]<In1[i], 21 greaterThan In0[i]>In1[i], 22 Centre of Mass In0=lstX In1=lstY In2=lstZ In3=lstValues, 23 round In0[i], 24 rint In0[i], 25 floor In0[i], 26 ceil In0[i], 27 trunc In0[i]" ,int,"");
 
   BBTK_OUTPUT(MathOperationVector,Out,"Output vector",std::vector<double>,"");
 
diff --git a/packages/vtk/src/bbvtkPolyDataToActor.cxx b/packages/vtk/src/bbvtkPolyDataToActor.cxx
index 06c9cc2..0002d6c 100644
--- a/packages/vtk/src/bbvtkPolyDataToActor.cxx
+++ b/packages/vtk/src/bbvtkPolyDataToActor.cxx
@@ -227,7 +227,7 @@ printf("EED WARNNING!  PolyDataToActor::DoProcess  which is the default values o
 //					polydatamapper->SetScalarModeToUseCellFieldData();	
 //					polydatamapper->SetScalarModeToUseFieldData();    //    1/2  	hausdorff->SetTargetDistanceMethodToPointToCell();
 //					polydatamapper->SetScalarModeToUsePointData();	 // *
-					polydatamapper->SetScalarModeToUsePointFieldData();					
+					polydatamapper->SetScalarModeToUsePointFieldData();
 					
 					polydatamapper->SetColorModeToMapScalars();
 					polydatamapper->SetLookupTable( bbGetInputScalarVisibilityOn_LookupTable() );
diff --git a/packages/vtk/src/bbvtkSurfaceTexture.cxx b/packages/vtk/src/bbvtkSurfaceTexture.cxx
index 1e002aa..ef9d87e 100644
--- a/packages/vtk/src/bbvtkSurfaceTexture.cxx
+++ b/packages/vtk/src/bbvtkSurfaceTexture.cxx
@@ -49,9 +49,16 @@ void SurfaceTexture::Process()
 		int maxX = ext[1]-ext[0]+1;
 		int maxY = ext[3]-ext[2]+1;
 		int maxZ = ext[5]-ext[4]+1;
-		if (firsttime==true)
+		
+		if (backColorType!=bbGetInputColorType() )
 		{
-			firsttime=false;
+			backColorType = bbGetInputColorType();
+			if (colors!=NULL)				{ colors->Delete(); 			}
+//			if (colorLookupTable!=NULL)		{ colorLookupTable->Delete(); 	}
+//			if (colorLookupTableWL!=NULL)	{ colorLookupTableWL->Delete(); }
+			
+			
+//			firsttime=false;
 			// Generate the colors for each point based on the color map
 			colors = vtkUnsignedCharArray::New(); 
 			colors->SetNumberOfComponents(3);
@@ -132,6 +139,9 @@ void SurfaceTexture::Process()
 	  		  colorLookupTable->SetTableValue(11,0.5,0.5,1	,1);
 			} // type 3
 		}  // firsttime
+		
+		
+		
 		bbGetInputMesh()->GetPointData()->SetScalars(colors);
 		if (bbGetInputColorType()==1)
 		{
@@ -198,7 +208,7 @@ void SurfaceTexture::bbUserSetDefaultValues()
 	bbSetInputTransform(NULL);
 	bbSetInputExternalLookupTable(NULL);
   
-	firsttime				= true;
+	backColorType			= -999;
 	colors					= NULL;
 	colorLookupTable		= NULL;
 	colorLookupTableWL		= NULL;
diff --git a/packages/vtk/src/bbvtkSurfaceTexture.h b/packages/vtk/src/bbvtkSurfaceTexture.h
index c8108c0..20032a5 100644
--- a/packages/vtk/src/bbvtkSurfaceTexture.h
+++ b/packages/vtk/src/bbvtkSurfaceTexture.h
@@ -36,7 +36,7 @@ class bbvtk_EXPORT SurfaceTexture
   void Process();
 
 
-	bool						firsttime;
+ 	int 						backColorType;
 	vtkUnsignedCharArray		*colors;
 	vtkScalarsToColors			*generalLookupTable;
 	vtkLookupTable				*colorLookupTable;
-- 
2.49.0