1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkTexture.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkTexture.h"
#include "vtkExecutive.h"
#include "vtkGraphicsFactory.h"
#include "vtkImageData.h"
#include "vtkLookupTable.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
vtkCxxRevisionMacro(vtkTexture, "$Revision: 1.53 $");
//----------------------------------------------------------------------------
// Needed when we don't use the vtkStandardNewMacro.
vtkInstantiatorNewMacro(vtkTexture);
//----------------------------------------------------------------------------
// Construct object and initialize.
vtkTexture::vtkTexture()
{
this->Repeat = 1;
this->Interpolate = 0;
this->Quality = VTK_TEXTURE_QUALITY_DEFAULT;
this->LookupTable = NULL;
this->MappedScalars = NULL;
this->MapColorScalarsThroughLookupTable = 0;
this->SelfAdjustingTableRange = 0;
this->SetNumberOfOutputPorts(0);
}
vtkTexture::~vtkTexture()
{
if (this->MappedScalars)
{
this->MappedScalars->Delete();
}
if (this->LookupTable != NULL)
{
this->LookupTable->UnRegister(this);
}
}
// return the correct type of Texture
vtkTexture *vtkTexture::New()
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkGraphicsFactory::CreateInstance("vtkTexture");
return (vtkTexture*)ret;
}
vtkImageData *vtkTexture::GetInput()
{
if (this->GetNumberOfInputConnections(0) < 1)
{
return 0;
}
return vtkImageData::SafeDownCast(this->GetExecutive()->GetInputData(0, 0));
}
void vtkTexture::SetLookupTable(vtkLookupTable *lut)
{
if ( this->LookupTable != lut )
{
if ( this->LookupTable != NULL ) {this->LookupTable->UnRegister(this);}
this->LookupTable = lut;
if ( this->LookupTable != NULL ) {this->LookupTable->Register(this);}
this->Modified();
}
}
void vtkTexture::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Interpolate: " << (this->Interpolate ? "On\n" : "Off\n");
os << indent << "Repeat: " << (this->Repeat ? "On\n" : "Off\n");
os << indent << "Quality: ";
switch (this->Quality)
{
case VTK_TEXTURE_QUALITY_DEFAULT:
os << "Default\n";
break;
case VTK_TEXTURE_QUALITY_16BIT:
os << "16Bit\n";
break;
case VTK_TEXTURE_QUALITY_32BIT:
os << "32Bit\n";
break;
}
os << indent << "MapColorScalarsThroughLookupTable: " << (this->MapColorScalarsThroughLookupTable ? "On\n" : "Off\n");
if ( this->GetInput() )
{
os << indent << "Input: (" << (void *)this->GetInput() << ")\n";
}
else
{
os << indent << "Input: (none)\n";
}
if ( this->LookupTable )
{
os << indent << "LookupTable:\n";
this->LookupTable->PrintSelf (os, indent.GetNextIndent ());
}
else
{
os << indent << "LookupTable: (none)\n";
}
if ( this->MappedScalars )
{
os << indent << "Mapped Scalars: " << this->MappedScalars << "\n";
}
else
{
os << indent << "Mapped Scalars: (none)\n";
}
}
unsigned char *vtkTexture::MapScalarsToColors (vtkDataArray *scalars)
{
int numPts = scalars->GetNumberOfTuples();
vtkUnsignedCharArray *mappedScalars;
// if there is no lookup table, create one
if (this->LookupTable == NULL)
{
this->LookupTable = vtkLookupTable::New();
this->LookupTable->Register(this);
this->LookupTable->Delete();
this->LookupTable->Build ();
this->SelfAdjustingTableRange = 1;
}
else
{
this->SelfAdjustingTableRange = 0;
}
// if there is no pixmap, create one
if (!this->MappedScalars)
{
this->MappedScalars = vtkUnsignedCharArray::New();
this->MappedScalars->SetNumberOfComponents(4);
}
// if the texture created its own lookup table, set the Table Range
// to the range of the scalar data.
if (this->SelfAdjustingTableRange)
{
this->LookupTable->SetTableRange (scalars->GetRange(0));
}
// map the scalars to colors
mappedScalars = this->MappedScalars;
mappedScalars->SetNumberOfTuples(numPts);
unsigned char *cptr = (unsigned char *)mappedScalars->GetVoidPointer(0);
this->LookupTable->MapScalarsThroughTable(scalars,cptr);
return cptr;
}
void vtkTexture::Render(vtkRenderer *ren)
{
vtkImageData *input = this->GetInput();
if (input) //load texture map
{
// We do not want more than requested.
input->RequestExactExtentOn();
// Updating the whole extent may not be necessary.
input->UpdateInformation();
input->SetUpdateExtentToWholeExtent();
input->Update();
this->Load(ren);
}
}
|