Commit 9b7de0b3 authored by Alvaro Sanchez's avatar Alvaro Sanchez Committed by Kitware Robot

Merge topic 'model-representation'

a0ea643f Added SMTKModelRepresentation plugin.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: David Thompson's avatarDavid Thompson <david.thompson@kitware.com>
Merge-request: !923
parents 54f27d91 a0ea643f
......@@ -7,3 +7,4 @@ if (PARAVIEW_BUILD_QT_GUI)
add_subdirectory(operators)
endif()
add_subdirectory(server)
add_subdirectory(representation)
include(${PARAVIEW_USE_FILE})
include(ParaViewPlugins)
set(REP_SOURCE
vtkSMSMTKModelRepresentationProxy.cxx
vtkSMTKModelRepresentation.cxx
)
set(REP_HEADER
vtkSMSMTKModelRepresentationProxy.h
vtkSMTKModelRepresentation.h
)
set(REP_XML
representation.xml
)
# Install the headers
smtk_public_headers(${REP_HEADER})
# Generate a ParaView plugin
add_paraview_plugin(
smtkRepresentationPlugin "1.0"
SERVER_MANAGER_SOURCES ${REP_SOURCE}
SERVER_MANAGER_XML ${REP_XML}
)
target_link_libraries(smtkRepresentationPlugin
LINK_PUBLIC
smtkCore
)
smtk_export_header(smtkRepresentationPlugin Exports.h)
<ServerManagerConfiguration>
<ProxyGroup name="representations">
<SMTKModelRepresentationProxy name="SMTKModelRepresentation"
class="vtkSMTKModelRepresentation"
processes="client|renderserver|dataserver"
base_proxygroup="internal_representations"
base_proxyname="SurfaceRepresentationBase">
<Documentation>
This specialized representation uses extended functionality of the
composite mapper to better integrate with SMTKModel. Handles selection
of SMTK Model entities.
</Documentation>
<InputProperty command="SetInputConnection"
name="Input">
<DataTypeDomain name="input_type">
<DataType value="vtkDataSet"/>
</DataTypeDomain>
<Documentation>Model entity tessellations input. </Documentation>
</InputProperty>
<InputProperty command="SetInputConnection"
label="Glyph prototypes"
name="GlyphPrototypes"
panel_visibility="advanced"
port_index="1">
<DataTypeDomain name="input_type">
<DataType value="vtkDataObjectTree"/>
</DataTypeDomain>
<Documentation>Glyph vertices.</Documentation>
<!--
<ProxyListDomain name="proxy_list">
<Proxy group="sources" name="ArrowSource" />
<Proxy group="sources" name="ConeSource" />
<Proxy group="sources" name="CubeSource" />
<Proxy group="sources" name="CylinderSource" />
<Proxy group="sources" name="LineSource" />
<Proxy group="sources" name="SphereSource" />
<Proxy group="sources" name="GlyphSource2D" />
<Proxy group="internal_filters" name="PipelineConnection" />
<Proxy group="sources" name="SMTKModelReader" />
</ProxyListDomain>
-->
</InputProperty>
<InputProperty command="SetInputConnection"
label="Glyph points"
name="GlyphPoints"
panel_visibility="advanced"
port_index="2">
<Documentation>Glyph source objects.</Documentation>
<DataTypeDomain name="input_type">
<DataType value="vtkPolyData" />
<DataType value="vtkCompositeDataSet" />
</DataTypeDomain>
<Hints>
<ProxyPropertyWidget selected_proxy_panel_visibility="advanced" />
<!-- show the selected proxy's panel, only in advanced mode. -->
</Hints>
</InputProperty>
<!-- End of SMTKModelRepresentation -->
</SMTKModelRepresentationProxy>
<Extension name="GeometryRepresentation">
<Documentation>
Extends standard GeometryRepresentation to serve as a SMTK model
representation.
</Documentation>
<!-- This adds to what is already defined in PVRepresentationBase -->
<RepresentationType subproxy="SMTKModelRepresentation"
text="SMTK Model" subtype="Surface" />
<SubProxy>
<Proxy name="SMTKModelRepresentation"
proxygroup="representations" proxyname="SMTKModelRepresentation">
</Proxy>
<ExposedProperties>
<PropertyGroup label="SMTK Model Parameters"
panel_visibility="always">
<Property name="GlyphPrototypes"
panel_visibility="always"/>
<Property name="GlyphPoints"
panel_visibility="always"/>
</PropertyGroup>
</ExposedProperties>
<ShareProperties subproxy="SurfaceRepresentation">
<Exception name="Input" />
<Exception name="Visibility" />
</ShareProperties>
</SubProxy>
</Extension>
</ProxyGroup>
</ServerManagerConfiguration>
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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 "vtkSMSMTKModelRepresentationProxy.h"
#include "vtkSMTKModelRepresentation.h"
#include "vtkClientServerStream.h"
#include "vtkObjectFactory.h"
#include "vtkPVExtractSelection.h"
#include "vtkPVXMLElement.h"
#include "vtkSMChartSeriesListDomain.h"
#include "vtkSMDomain.h"
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
vtkStandardNewMacro(vtkSMSMTKModelRepresentationProxy);
vtkSMSMTKModelRepresentationProxy::vtkSMSMTKModelRepresentationProxy() = default;
vtkSMSMTKModelRepresentationProxy::~vtkSMSMTKModelRepresentationProxy() = default;
vtkSMTKModelRepresentation* vtkSMSMTKModelRepresentationProxy::GetRepresentation()
{
this->CreateVTKObjects();
return vtkSMTKModelRepresentation::SafeDownCast(this->GetClientSideObject());
}
void vtkSMSMTKModelRepresentationProxy::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
void vtkSMSMTKModelRepresentationProxy::SetPropertyModifiedFlag(const char* name, int flag)
{
if (!name)
{
return;
}
if (strcmp(name, "Input") == 0)
{
vtkSMPropertyHelper helper(this, name);
vtkSMSourceProxy* input = vtkSMSourceProxy::SafeDownCast(helper.GetAsProxy(0));
if (input)
{
auto source = vtkSMSourceProxy::SafeDownCast(input->GetTrueParentProxy());
if (source)
{
vtkSMPropertyHelper(this, "GlyphPrototypes", true).Set(source, 1);
vtkSMPropertyHelper(this, "GlyphPoints", true).Set(source, 2);
this->UpdateVTKObjects();
}
}
}
this->Superclass::SetPropertyModifiedFlag(name, flag);
}
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//=========================================================================
/**
* @class vtkSMSMTKModelRepresentationProxy
*
* Updates additional input properties of the representation
* (GlyphPrototypes and GlyphPoints).
*/
#ifndef vtkSMSMTKModelRepresentationProxy_h
#define vtkSMSMTKModelRepresentationProxy_h
#include "smtk/extension/paraview/representation/Exports.h" //needed for exports
#include "vtkSMRepresentationProxy.h"
class vtkSMTKModelRepresentation;
class SMTKREPRESENTATIONPLUGIN_EXPORT vtkSMSMTKModelRepresentationProxy
: public vtkSMRepresentationProxy
{
public:
static vtkSMSMTKModelRepresentationProxy* New();
vtkTypeMacro(vtkSMSMTKModelRepresentationProxy, vtkSMRepresentationProxy);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Returns client side representation object.
*/
vtkSMTKModelRepresentation* GetRepresentation();
protected:
vtkSMSMTKModelRepresentationProxy();
~vtkSMSMTKModelRepresentationProxy() override;
/**
* Overridden to ensure that whenever "Input" property changes, other input
* properties are updated (glyph mapper inputs).
*/
void SetPropertyModifiedFlag(const char* name, int flag) override;
private:
vtkSMSMTKModelRepresentationProxy(const vtkSMSMTKModelRepresentationProxy&) = delete;
void operator=(const vtkSMSMTKModelRepresentationProxy&) = delete;
};
#endif
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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 <vtkActor.h>
#include <vtkAlgorithmOutput.h>
#include <vtkCompositeDataDisplayAttributes.h>
#include <vtkCompositePolyDataMapper2.h>
#include <vtkGlyph3DMapper.h>
#include <vtkInformation.h>
#include <vtkInformationVector.h>
#include <vtkMath.h>
#include <vtkMatrix4x4.h>
#include <vtkObjectFactory.h>
#include <vtkRenderer.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkPVCacheKeeper.h>
#include <vtkPVRenderView.h>
#include <vtkPVTrivialProducer.h>
#include "vtkSMTKModelRepresentation.h"
vtkStandardNewMacro(vtkSMTKModelRepresentation);
vtkSMTKModelRepresentation::vtkSMTKModelRepresentation()
: EntityMapper(vtkSmartPointer<vtkCompositePolyDataMapper2>::New())
, SelectedEntityMapper(vtkSmartPointer<vtkCompositePolyDataMapper2>::New())
, GlyphMapper(vtkSmartPointer<vtkGlyph3DMapper>::New())
, SelectedGlyphMapper(vtkSmartPointer<vtkGlyph3DMapper>::New())
, Entities(vtkSmartPointer<vtkActor>::New())
, SelectedEntities(vtkSmartPointer<vtkActor>::New())
, GlyphEntities(vtkSmartPointer<vtkActor>::New())
, SelectedGlyphEntities(vtkSmartPointer<vtkActor>::New())
{
this->SetupDefaults();
this->SetNumberOfInputPorts(3);
}
vtkSMTKModelRepresentation::~vtkSMTKModelRepresentation() = default;
void vtkSMTKModelRepresentation::SetupDefaults()
{
auto compAtt = vtkCompositeDataDisplayAttributes::New();
this->EntityMapper->SetCompositeDataDisplayAttributes(compAtt);
this->Entities->SetMapper(this->EntityMapper);
this->SelectedEntities->SetMapper(this->SelectedEntityMapper);
this->GlyphEntities->SetMapper(this->GlyphMapper);
this->SelectedGlyphEntities->SetMapper(this->SelectedGlyphMapper);
}
int vtkSMTKModelRepresentation::RequestData(
vtkInformation* request, vtkInformationVector** inVec, vtkInformationVector* outVec)
{
vtkMath::UninitializeBounds(this->DataBounds);
if (inVec[0]->GetNumberOfInformationObjects() == 1)
{
vtkInformation* inInfo = inVec[0]->GetInformationObject(0);
this->SetOutputExtent(this->GetInternalOutputPort(0), inInfo);
// Model entities
this->CacheKeeper->SetInputConnection(this->GetInternalOutputPort(0));
// Glyph points (2) and prototypes (1)
this->GlyphMapper->SetInputConnection(this->GetInternalOutputPort(2));
this->GlyphMapper->SetInputConnection(1, this->GetInternalOutputPort(1));
this->GlyphMapper->SetUseSourceTableTree(true);
}
this->CacheKeeper->Update();
this->EntityMapper->Modified();
this->GlyphMapper->Modified();
// // Determine data bounds
// this->GetBounds(this->GetOutputDataObject(0), this->DataBounds,
// this->EntityMapper->GetCompositeDataDisplayAttributes());
return vtkPVDataRepresentation::RequestData(request, inVec, outVec);
}
int vtkSMTKModelRepresentation::ProcessViewRequest(
vtkInformationRequestKey* request_type, vtkInformation* inInfo, vtkInformation* outInfo)
{
if (!vtkPVDataRepresentation::ProcessViewRequest(request_type, inInfo, outInfo))
{
// i.e. this->GetVisibility() == false, hence nothing to do.
return 0;
}
if (request_type == vtkPVView::REQUEST_UPDATE())
{
// provide the "geometry" to the view so the view can delivery it to the
// rendering nodes as and when needed.
// When this process doesn't have any valid input, the cache-keeper is setup
// to provide a place-holder dataset of the right type. This is essential
// since the vtkPVRenderView uses the type specified to decide on the
// delivery mechanism, among other things.
vtkPVRenderView::SetPiece(inInfo, this, this->CacheKeeper->GetOutputDataObject(0), 0, 0);
// Since we are rendering polydata, it can be redistributed when ordered
// compositing is needed. So let the view know that it can feel free to
// redistribute data as and when needed.
vtkPVRenderView::MarkAsRedistributable(inInfo, this);
// Tell the view if this representation needs ordered compositing. We need
// ordered compositing when rendering translucent geometry. We need to extend
// this condition to consider translucent LUTs once we start supporting them.
if (this->Entities->HasTranslucentPolygonalGeometry())
{
outInfo->Set(vtkPVRenderView::NEED_ORDERED_COMPOSITING(), 1);
// Pass partitioning information to the render view.
if (this->UseDataPartitions == true)
{
vtkPVRenderView::SetOrderedCompositingInformation(inInfo, this->DataBounds);
}
}
// Finally, let the view know about the geometry bounds. The view uses this
// information for resetting camera and clip planes. Since this
// representation allows users to transform the geometry, we need to ensure
// that the bounds we report include the transformation as well.
vtkNew<vtkMatrix4x4> matrix;
this->Entities->GetMatrix(matrix.GetPointer());
vtkPVRenderView::SetGeometryBounds(inInfo, this->DataBounds, matrix.GetPointer());
}
else if (request_type == vtkPVView::REQUEST_UPDATE_LOD())
{
/// TODO Add LOD Mappers
}
else if (request_type == vtkPVView::REQUEST_RENDER())
{
auto producerPort = vtkPVRenderView::GetPieceProducer(inInfo, this, 0);
this->EntityMapper->SetInputConnection(0, producerPort);
auto data = producerPort->GetProducer()->GetOutputDataObject(0);
if (this->BlockAttributeTime < data->GetMTime() || this->BlockAttrChanged)
{
this->UpdateBlockAttributes(this->EntityMapper.GetPointer());
this->BlockAttributeTime.Modified();
this->BlockAttrChanged = false;
}
}
return 1;
}
void vtkSMTKModelRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
this->vtkPVDataRepresentation::PrintSelf(os, indent);
}
void vtkSMTKModelRepresentation::SetOutputExtent(vtkAlgorithmOutput* output, vtkInformation* inInfo)
{
if (inInfo->Has(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()))
{
vtkPVTrivialProducer* prod = vtkPVTrivialProducer::SafeDownCast(output->GetProducer());
if (prod)
{
prod->SetWholeExtent(inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
}
}
}
bool vtkSMTKModelRepresentation::AddToView(vtkView* view)
{
vtkPVRenderView* rview = vtkPVRenderView::SafeDownCast(view);
if (rview)
{
rview->GetRenderer()->AddActor(this->Entities);
rview->GetRenderer()->AddActor(this->GlyphEntities);
// Indicate that this is prop that we are rendering when hardware selection
// is enabled.
rview->RegisterPropForHardwareSelection(this, this->Entities);
rview->RegisterPropForHardwareSelection(this, this->GlyphEntities);
return this->vtkPVDataRepresentation::AddToView(view);
}
return false;
}
bool vtkSMTKModelRepresentation::RemoveFromView(vtkView* view)
{
vtkPVRenderView* rview = vtkPVRenderView::SafeDownCast(view);
if (rview)
{
rview->GetRenderer()->RemoveActor(this->Entities);
rview->GetRenderer()->RemoveActor(this->GlyphEntities);
rview->UnRegisterPropForHardwareSelection(this, this->Entities);
rview->UnRegisterPropForHardwareSelection(this, this->GlyphEntities);
return this->vtkPVDataRepresentation::RemoveFromView(view);
}
return false;
}
void vtkSMTKModelRepresentation::SetVisibility(bool val)
{
this->Entities->SetVisibility(val);
this->GlyphEntities->SetVisibility(val);
this->vtkPVDataRepresentation::SetVisibility(val);
}
int vtkSMTKModelRepresentation::FillInputPortInformation(int port, vtkInformation* info)
{
// Saying INPUT_IS_OPTIONAL() is essential, since representations don't have
// any inputs on client-side (in client-server, client-render-server mode) and
// render-server-side (in client-render-server mode).
if (port == 0)
{
// Entity tessellations
info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkCompositeDataSet");
return 1;
}
if (port == 1)
{
// Glyph vertices
info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkCompositeDataSet");
return 1;
}
else if (port == 2)
{
// Glyph sources
info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObjectTree");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
return 1;
}
return 0;
}
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//=========================================================================
#ifndef vtkSMTKModelRepresentation_h
#define vtkSMTKModelRepresentation_h
#include "smtk/extension/paraview/representation/Exports.h"
#include "vtkGeometryRepresentation.h"
#include <vtkSmartPointer.h>
class vtkActor;
class vtkCompositePolyDataMapper2;
class vtkGlyph3DMapper;
class vtkSelection;
/**
* \brief Representation of an SMTK Model.
* Renders the outputs of vtkSMTKModelReader.
* - Port 0: Model entities
* - Port 1: Glyph prototypes
* - Port 2: Glyph points
*
* vtkSMSMTKModelRepresentationProxy sets certain properties used as
* mapper inputs (GlyphPrototypes and GlyphPoints).
*/
class SMTKREPRESENTATIONPLUGIN_EXPORT vtkSMTKModelRepresentation : public vtkGeometryRepresentation
{
public:
static vtkSMTKModelRepresentation* New();
vtkTypeMacro(vtkSMTKModelRepresentation, vtkGeometryRepresentation);
void PrintSelf(ostream& os, vtkIndent indent) override;
int ProcessViewRequest(vtkInformationRequestKey* request_type, vtkInformation* inInfo,
vtkInformation* outInfo) override;
int RequestData(
vtkInformation* info, vtkInformationVector** inVec, vtkInformationVector* outVec) override;
bool AddToView(vtkView* view) override;
bool RemoveFromView(vtkView* view) override;
void SetVisibility(bool val) override;
protected:
vtkSMTKModelRepresentation();
~vtkSMTKModelRepresentation();
int FillInputPortInformation(int port, vtkInformation* info) override;
void SetupDefaults() override;
void SetOutputExtent(vtkAlgorithmOutput* output, vtkInformation* inInfo);
vtkSmartPointer<vtkCompositePolyDataMapper2> EntityMapper;
vtkSmartPointer<vtkCompositePolyDataMapper2> SelectedEntityMapper;
vtkSmartPointer<vtkGlyph3DMapper> GlyphMapper;
vtkSmartPointer<vtkGlyph3DMapper> SelectedGlyphMapper;
vtkSmartPointer<vtkActor> Entities;
vtkSmartPointer<vtkActor> SelectedEntities;
vtkSmartPointer<vtkActor> GlyphEntities;
vtkSmartPointer<vtkActor> SelectedGlyphEntities;
private:
vtkSMTKModelRepresentation(const vtkSMTKModelRepresentation&) = delete;
void operator=(const vtkSMTKModelRepresentation&) = delete;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment