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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
/*=========================================================================
Program: ParaView
Module: vtkGeometryRepresentationWithFaces.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkGeometryRepresentationWithFaces.h"
#include "vtkCompositePolyDataMapper2.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkProperty.h"
#include "vtkPVLODActor.h"
#include "vtkPVRenderView.h"
#include "vtkRenderer.h"
vtkStandardNewMacro(vtkGeometryRepresentationWithFaces);
//----------------------------------------------------------------------------
vtkGeometryRepresentationWithFaces::vtkGeometryRepresentationWithFaces()
{
this->BackfaceActor = vtkPVLODActor::New();
this->BackfaceProperty = vtkProperty::New();
this->BackfaceMapper = vtkCompositePolyDataMapper2::New();
this->LODBackfaceMapper = vtkCompositePolyDataMapper2::New();
this->BackfaceRepresentation = FOLLOW_FRONTFACE;
// Since we are overriding SetupDefaults(), we need to call it again.
this->SetupDefaults();
}
//----------------------------------------------------------------------------
vtkGeometryRepresentationWithFaces::~vtkGeometryRepresentationWithFaces()
{
this->BackfaceActor->Delete();
this->BackfaceProperty->Delete();
this->BackfaceMapper->Delete();
this->LODBackfaceMapper->Delete();
}
//----------------------------------------------------------------------------
void vtkGeometryRepresentationWithFaces::SetupDefaults()
{
this->Superclass::SetupDefaults();
this->BackfaceActor->SetProperty(this->BackfaceProperty);
this->BackfaceActor->SetMapper(this->BackfaceMapper);
this->BackfaceActor->SetLODMapper(this->LODBackfaceMapper);
}
//----------------------------------------------------------------------------
int vtkGeometryRepresentationWithFaces::ProcessViewRequest(
vtkInformationRequestKey* request_type,
vtkInformation* inInfo, vtkInformation* outInfo)
{
if (!this->Superclass::ProcessViewRequest(request_type, inInfo, outInfo))
{
return 0;
}
if (request_type == vtkPVView::REQUEST_RENDER())
{
vtkAlgorithmOutput* producerPort = vtkPVRenderView::GetPieceProducer(inInfo, this);
if (inInfo->Has(vtkPVRenderView::USE_LOD()))
{
this->LODBackfaceMapper->SetInputConnection(0, producerPort);
}
else
{
this->BackfaceMapper->SetInputConnection(0, producerPort);
}
}
return 1;
}
//----------------------------------------------------------------------------
void vtkGeometryRepresentationWithFaces::SetVisibility(bool val)
{
this->Superclass::SetVisibility(val);
if (!val)
{
this->BackfaceActor->SetVisibility(0);
}
}
//----------------------------------------------------------------------------
bool vtkGeometryRepresentationWithFaces::AddToView(vtkView* view)
{
// FIXME: Need generic view API to add props.
vtkPVRenderView* rview = vtkPVRenderView::SafeDownCast(view);
if (rview)
{
rview->GetRenderer()->AddActor(this->BackfaceActor);
}
return this->Superclass::AddToView(view);
}
//----------------------------------------------------------------------------
bool vtkGeometryRepresentationWithFaces::RemoveFromView(vtkView* view)
{
vtkPVRenderView* rview = vtkPVRenderView::SafeDownCast(view);
if (rview)
{
rview->GetRenderer()->RemoveActor(this->BackfaceActor);
}
return this->Superclass::RemoveFromView(view);
}
//----------------------------------------------------------------------------
void vtkGeometryRepresentationWithFaces::UpdateColoringParameters()
{
this->Superclass::UpdateColoringParameters();
switch (this->BackfaceRepresentation)
{
case FOLLOW_FRONTFACE:
this->BackfaceActor->SetVisibility(0);
this->Property->SetBackfaceCulling(0);
this->Property->SetFrontfaceCulling(0);
break;
case CULL_BACKFACE:
this->BackfaceActor->SetVisibility(0);
this->Property->SetBackfaceCulling(1);
this->Property->SetFrontfaceCulling(0);
break;
case CULL_FRONTFACE:
this->BackfaceActor->SetVisibility(0);
this->Property->SetBackfaceCulling(0);
this->Property->SetFrontfaceCulling(1);
break;
case SURFACE_WITH_EDGES:
this->BackfaceActor->SetVisibility(this->GetVisibility());
this->Property->SetBackfaceCulling(1);
this->Property->SetFrontfaceCulling(0);
this->BackfaceProperty->SetBackfaceCulling(0);
this->BackfaceProperty->SetFrontfaceCulling(1);
this->BackfaceProperty->SetEdgeVisibility(1);
this->BackfaceProperty->SetRepresentation(VTK_SURFACE);
break;
default:
this->BackfaceActor->SetVisibility(this->GetVisibility());
this->Property->SetBackfaceCulling(1);
this->Property->SetFrontfaceCulling(0);
this->BackfaceProperty->SetBackfaceCulling(0);
this->BackfaceProperty->SetFrontfaceCulling(1);
this->BackfaceProperty->SetEdgeVisibility(0);
this->BackfaceProperty->SetRepresentation(this->BackfaceRepresentation);
}
if (this->BackfaceActor->GetVisibility())
{
// Adjust material properties.
double diffuse = this->Diffuse;
double specular = this->Specular;
double ambient = this->Ambient;
if (this->BackfaceRepresentation != SURFACE &&
this->BackfaceRepresentation != SURFACE_WITH_EDGES)
{
diffuse = 0.0;
ambient = 1.0;
specular = 0.0;
}
else if (this->Mapper->GetScalarVisibility())
{
specular = 0.0;
}
this->BackfaceProperty->SetAmbient(ambient);
this->BackfaceProperty->SetSpecular(specular);
this->BackfaceProperty->SetDiffuse(diffuse);
// Copy paramters from this->Mapper
this->BackfaceMapper->SetLookupTable(this->Mapper->GetLookupTable());
this->BackfaceMapper->SetColorMode(this->Mapper->GetColorMode());
this->BackfaceMapper->SetInterpolateScalarsBeforeMapping(
this->Mapper->GetInterpolateScalarsBeforeMapping());
this->BackfaceMapper->SetStatic(this->Mapper->GetStatic());
this->BackfaceMapper->SetScalarVisibility(this->Mapper->GetScalarVisibility());
this->BackfaceMapper->SelectColorArray(this->Mapper->GetArrayName());
this->BackfaceMapper->SetScalarMode(this->Mapper->GetScalarMode());
// Copy paramters from this->LODMapper
this->LODBackfaceMapper->SetLookupTable(this->LODMapper->GetLookupTable());
this->LODBackfaceMapper->SetColorMode(this->LODMapper->GetColorMode());
this->LODBackfaceMapper->SetInterpolateScalarsBeforeMapping(
this->LODMapper->GetInterpolateScalarsBeforeMapping());
this->LODBackfaceMapper->SetStatic(this->LODMapper->GetStatic());
this->LODBackfaceMapper->SetScalarVisibility(this->LODMapper->GetScalarVisibility());
this->LODBackfaceMapper->SelectColorArray(this->LODMapper->GetArrayName());
this->LODBackfaceMapper->SetScalarMode(this->LODMapper->GetScalarMode());
// Copy parameters from this->Property
this->BackfaceProperty->SetEdgeColor(this->Property->GetEdgeColor());
this->BackfaceProperty->SetInterpolation(this->Property->GetInterpolation());
this->BackfaceProperty->SetLineWidth(this->Property->GetLineWidth());
this->BackfaceProperty->SetPointSize(this->Property->GetPointSize());
this->BackfaceProperty->SetSpecularColor(this->Property->GetSpecularColor());
this->BackfaceProperty->SetSpecularPower(this->Property->GetSpecularPower());
// Copy parameters from this->Actor
this->BackfaceActor->SetOrientation(this->Actor->GetOrientation());
this->BackfaceActor->SetOrigin(this->Actor->GetOrigin());
this->BackfaceActor->SetPickable(this->Actor->GetPickable());
this->BackfaceActor->SetPosition(this->Actor->GetPosition());
this->BackfaceActor->SetScale(this->Actor->GetScale());
this->BackfaceActor->SetTexture(this->Actor->GetTexture());
}
}
//----------------------------------------------------------------------------
void vtkGeometryRepresentationWithFaces::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//***************************************************************************
// Forwaded to vtkProperty(BackfaceProperty)
//----------------------------------------------------------------------------
void vtkGeometryRepresentationWithFaces::SetBackfaceAmbientColor(
double r, double g, double b)
{
this->BackfaceProperty->SetAmbientColor(r, g, b);
}
//----------------------------------------------------------------------------
void vtkGeometryRepresentationWithFaces::SetBackfaceDiffuseColor(double r, double g, double b)
{
this->BackfaceProperty->SetDiffuseColor(r, g, b);
}
//----------------------------------------------------------------------------
void vtkGeometryRepresentationWithFaces::SetBackfaceOpacity(double val)
{
this->BackfaceProperty->SetOpacity(val);
}
|