/* # --------------------------------------------------------------------- # # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image # pour la Sante) # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton # Previous Authors : Laurent Guigues, Jean-Pierre Roux # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil # # This software is governed by the CeCILL-B license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL-B # license as circulated by CEA, CNRS and INRIA at the following URL # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html # or in the file LICENSE.txt. # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ #include "vtkVectorsTensorsVisuBase.h" #include "vtkObjectFactory.h" vtkStandardNewMacro(vtkLookupTableDirectionVector); // Construct with range=(0,1); and hsv ranges set up for rainbow color table // (from red to blue). vtkLookupTableDirectionVector::vtkLookupTableDirectionVector(int sze, int ext) { this->TableRange[0] = 0.0; this->TableRange[1] = 1.0; } //---------------------------------------------------------------------------- vtkLookupTableDirectionVector::~vtkLookupTableDirectionVector() { } unsigned char *vtkLookupTableDirectionVector::MapValue(double v) { //int idx = this->GetIndex(v); //return (this->Table->GetPointer(0) + 4*idx); return 0; } void vtkLookupTableDirectionVector::GetColor(double v, double rgb[3]) { // unsigned char *rgb8 = this->MapValue(v); // rgb[0] = rgb8[0]/255.0; // rgb[1] = rgb8[1]/255.0; // rgb[2] = rgb8[2]/255.0; rgb[0] = 1; rgb[1] = 1; rgb[2] = 0; } void vtkLookupTableDirectionVector::SetTableRange(double r[2]) { this->SetTableRange(r[0],r[1]); } //---------------------------------------------------------------------------- // Set the minimum/maximum scalar values for scalar mapping. Scalar values // less than minimum range value are clamped to minimum range value. // Scalar values greater than maximum range value are clamped to maximum // range value. void vtkLookupTableDirectionVector::SetTableRange(double rmin, double rmax) { if (rmax < rmin) { vtkErrorMacro("Bad table range: ["<TableRange[0] == rmin && this->TableRange[1] == rmax) { return; } this->TableRange[0] = rmin; this->TableRange[1] = rmax; this->Modified(); } //---------------------------------------------------------------------------- // Although this is a relatively expensive calculation, // it is only done on the first render. Colors are cached // for subsequent renders. template void vtkLookupTableMapDirVectorEED(vtkLookupTableDirectionVector *self, T *input, unsigned char *output, int length, int inIncr, int outFormat) { double tmp,sum; // double *mag; int i, j; double dirx,diry,dirz; inIncr=3; printf("EED length %d %p\n", length,input); // mag = new double[length]; for (i = 0; i < length; ++i) { dirx = 0; diry = 0; dirz = 0; sum = 0; for (j = 0; j < inIncr; ++j) { if (j==0) dirx= static_cast(*input); if (j==1) diry= static_cast(*input); if (j==2) dirz= static_cast(*input); tmp = static_cast(*input); sum += (tmp * tmp); ++input; } sum=sqrt(sum); *output++ = (unsigned char) abs( (255*dirx/sum) ); *output++ = (unsigned char) abs( (255*diry/sum) ); *output++ = (unsigned char) abs( (255*dirz/sum) ); *output++ = 255; // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum)); // printf(" C %d %f %f %f \n",inIncr,dirx,diry,dirz); } // vtkLookupTableMapData(self, mag, output, length, 1, outFormat); // delete [] mag; } //---------------------------------------------------------------------------- void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat) { printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d inputDataType=%d\n",inputIncrement,inputDataType); // if (this->UseMagnitude && inputIncrement > 1) // { switch (inputDataType) { vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast(input),output, numberOfValues,inputIncrement,outputFormat); return ); case VTK_BIT: vtkErrorMacro("Cannot comput magnitude of bit array."); break; default: vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType"); } /// switch // } //if } //---------------------------------------------------------------------------- void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); } //---------------------------------- //---------------------------------- //---------------------------------- //---------------------------------- //---------------------------------- vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase() { _firsttime = true; _active = false; _scalefactor= 1; _opacity = 1; _dataobject = NULL; _renderer = NULL; _typeForm = 0; _LutEED = vtkLookupTableDirectionVector::New(); //_LutEED->SetVectorMode(0); //_LutEED->SetVectorModeToMagnitude(); //_LutEED->SetVectorModeToComponent(); _LutEED->SetVectorModeToRGBColors(); _pdm = vtkPolyDataMapper::New(); _actor = vtkActor::New(); _actorAdded = false; } vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase() { } //------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject) { _dataobject = dataobject; } //------------------------------------------------------------------------ vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject() { return _dataobject; } //------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer) { _renderer=renderer; } //------------------------------------------------------------------------ vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer() { return _renderer; } //------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor) { _scalefactor=scalefactor; } //------------------------------------------------------------------------ double vtkVectorsTensorsVisuBase::GetScaleFactor() { return _scalefactor; } //------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetActive(bool active) { _active = active; } //------------------------------------------------------------------------ bool vtkVectorsTensorsVisuBase::GetActive() { return _active; } //------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetOpacity(double opacity) { _opacity = opacity; } //------------------------------------------------------------------------ double vtkVectorsTensorsVisuBase::GetOpacity() { return _opacity; } //------------------------------------------------------------------------ vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D() { return _actor; } //------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm) { _typeForm=typeForm; } //------------------------------------------------------------------------ int vtkVectorsTensorsVisuBase::GetTypeForm() { return _typeForm; } //------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::Process() // virtual { } //------------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::VisibilityActor() { if ( (_active==true) && (_actorAdded==false) ){ if (GetRenderer()!=NULL) { GetRenderer()->AddActor(_actor); _actorAdded=true; } // if Renderer } // if _active==true if ( (_active==false) && (_actorAdded==true) ){ if (GetRenderer()!=NULL) { GetRenderer()->RemoveActor(_actor); _actorAdded=false; } // if Renderer } // if _active==false } //------------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw) { _colorlaw = colorlaw; } //------------------------------------------------------------------------------ void vtkVectorsTensorsVisuBase::SetColor(std::vector rgb) { if (rgb.size()==3) { _colorR=rgb[0]; _colorG=rgb[1]; _colorB=rgb[2]; } else { _colorR=1; _colorG=1; _colorB=1; } }