Commit ce1b5c0f authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

Added support to compute bounds for data correctly.

We now expect representations to report bounds. This has to be done to avoid the
dependence on geometry to be available for rendering.
parent 85a8d7b6
......@@ -15,11 +15,14 @@
#include "vtkGeometryRepresentation.h"
#include "vtkAlgorithmOutput.h"
#include "vtkBoundingBox.h"
#include "vtkCommand.h"
#include "vtkCompositeDataSet.h"
#include "vtkCompositeDataIterator.h"
#include "vtkCompositePolyDataMapper2.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
#include "vtkMultiBlockDataSetAlgorithm.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiProcessController.h"
......@@ -115,6 +118,8 @@ vtkGeometryRepresentation::vtkGeometryRepresentation()
this->AllowSpecularHighlightingWithScalarColoring = false;
vtkMath::UninitializeBounds(this->DataBounds);
this->SetupDefaults();
}
......@@ -140,9 +145,6 @@ void vtkGeometryRepresentation::SetupDefaults()
this->Decimator->SetCopyCellData(1);
this->Decimator->SetUseInternalTriangles(0);
this->Decimator->SetNumberOfDivisions(10, 10, 10);
// FIXME:STREAMING
//this->LODDeliveryFilter->SetLODMode(true); // tell the filter that it is
// // connected to the LOD pipeline.
vtkPVGeometryFilter::SafeDownCast(this->GeometryFilter)->SetUseOutline(0);
vtkPVGeometryFilter::SafeDownCast(this->GeometryFilter)->SetNonlinearSubdivisionLevel(1);
......@@ -153,11 +155,6 @@ void vtkGeometryRepresentation::SetupDefaults()
this->CacheKeeper->SetInputConnection(this->MultiBlockMaker->GetOutputPort());
this->Decimator->SetInputConnection(this->CacheKeeper->GetOutputPort());
// FIXME:STREAMING - Mapper's inputs are directly the data-objects provided by
// the view.
//this->Mapper->SetInputConnection(this->UpdateSuppressor->GetOutputPort());
//this->LODMapper->SetInputConnection(this->LODUpdateSuppressor->GetOutputPort());
this->Actor->SetMapper(this->Mapper);
this->Actor->SetLODMapper(this->LODMapper);
this->Actor->SetProperty(this->Property);
......@@ -209,6 +206,13 @@ int vtkGeometryRepresentation::ProcessViewRequest(
{
outInfo->Set(vtkPVRenderView::NEED_ORDERED_COMPOSITING(), 1);
}
// Set the data-bounds.
//double bounds[6];
vtkNew<vtkMatrix4x4> matrix;
this->Actor->GetMatrix(matrix.GetPointer());
vtkPVRenderView::SetGeometryBounds(
inInfo, this->DataBounds, matrix.GetPointer());
}
else if (request_type == vtkPVView::REQUEST_UPDATE_LOD())
{
......@@ -310,6 +314,8 @@ int vtkGeometryRepresentation::RequestData(vtkInformation* request,
{
// cout << this << ":" << this->DebugString << ":RequestData" << endl;
vtkMath::UninitializeBounds(this->DataBounds);
// Pass caching information to the cache keeper.
this->CacheKeeper->SetCachingEnabled(this->GetUseCache());
this->CacheKeeper->SetCacheTime(this->GetCacheKey());
......@@ -340,6 +346,29 @@ int vtkGeometryRepresentation::RequestData(vtkInformation* request,
this->GeometryFilter)->SetInputData(0, placeholder.GetPointer());
}
this->CacheKeeper->Update();
// Determine data bounds.
vtkCompositeDataSet* cd = vtkCompositeDataSet::SafeDownCast(
this->CacheKeeper->GetOutputDataObject(0));
if (cd)
{
vtkBoundingBox bbox;
vtkCompositeDataIterator* iter = cd->NewIterator();
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkDataSet* ds = vtkDataSet::SafeDownCast(iter->GetCurrentDataObject());
if (ds)
{
bbox.AddBounds(ds->GetBounds());
}
}
iter->Delete();
if (bbox.IsValid())
{
bbox.GetBounds(this->DataBounds);
}
}
return this->Superclass::RequestData(request, inputVector, outputVector);
}
......
......@@ -259,6 +259,7 @@ protected:
bool SuppressLOD;
bool AllowSpecularHighlightingWithScalarColoring;
bool RequestGhostCellsIfNeeded;
double DataBounds[6];
private:
vtkGeometryRepresentation(const vtkGeometryRepresentation&); // Not implemented
......
......@@ -134,6 +134,13 @@ int vtkImageSliceRepresentation::ProcessViewRequest(
// to provide a place-holder dataset of the right type.
vtkPVRenderView::SetPiece(inInfo, this,
this->CacheKeeper->GetOutputDataObject(0));
vtkImageData* img = vtkImageData::SafeDownCast(
this->CacheKeeper->GetOutputDataObject(0));
if (img)
{
vtkPVRenderView::SetGeometryBounds(inInfo, img->GetBounds());
}
}
else if (request_type == vtkPVView::REQUEST_RENDER())
{
......
......@@ -16,10 +16,10 @@
#include "vtkAlgorithmOutput.h"
#include "vtkCommand.h"
#include "vtkSmartVolumeMapper.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkOutlineSource.h"
#include "vtkPolyDataMapper.h"
......@@ -28,6 +28,7 @@
#include "vtkPVRenderView.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkSmartVolumeMapper.h"
#include "vtkVolumeProperty.h"
#include <map>
......@@ -56,6 +57,8 @@ vtkImageVolumeRepresentation::vtkImageVolumeRepresentation()
this->CacheKeeper->SetInputData(this->Cache);
this->Actor->SetLODMapper(this->OutlineMapper);
vtkMath::UninitializeBounds(this->DataBounds);
}
//----------------------------------------------------------------------------
......@@ -102,6 +105,7 @@ int vtkImageVolumeRepresentation::ProcessViewRequest(
this->OutlineSource->GetOutputDataObject(0));
outInfo->Set(vtkPVRenderView::NEED_ORDERED_COMPOSITING(), 1);
vtkPVRenderView::SetGeometryBounds(inInfo, this->DataBounds);
}
else if (request_type == vtkPVView::REQUEST_RENDER())
{
......@@ -120,6 +124,8 @@ int vtkImageVolumeRepresentation::ProcessViewRequest(
int vtkImageVolumeRepresentation::RequestData(vtkInformation* request,
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
vtkMath::UninitializeBounds(this->DataBounds);
// Pass caching information to the cache keeper.
this->CacheKeeper->SetCachingEnabled(this->GetUseCache());
this->CacheKeeper->SetCacheTime(this->GetCacheKey());
......@@ -139,6 +145,7 @@ int vtkImageVolumeRepresentation::RequestData(vtkInformation* request,
this->OutlineSource->SetBounds(vtkImageData::SafeDownCast(
this->CacheKeeper->GetOutputDataObject(0))->GetBounds());
this->OutlineSource->GetBounds(this->DataBounds);
}
else
{
......
......@@ -158,6 +158,7 @@ protected:
int ColorAttributeType;
char* ColorArrayName;
int RequestedRenderMode;
double DataBounds[6];
private:
vtkImageVolumeRepresentation(const vtkImageVolumeRepresentation&); // Not implemented
......
......@@ -32,6 +32,7 @@
#include "vtkLight.h"
#include "vtkLightKit.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
#include "vtkMemberFunctionCommand.h"
#include "vtkMPIMoveData.h"
#include "vtkMultiProcessController.h"
......@@ -90,7 +91,6 @@ vtkInformationKeyMacro(vtkPVRenderView, USE_LOD, Integer);
vtkInformationKeyMacro(vtkPVRenderView, LOD_RESOLUTION, Double);
vtkInformationKeyMacro(vtkPVRenderView, NEED_ORDERED_COMPOSITING, Integer);
vtkInformationKeyMacro(vtkPVRenderView, REPRESENTED_DATA_STORE, ObjectBase);
vtkInformationKeyRestrictedMacro(vtkPVRenderView, GEOMETRY_BOUNDS, DoubleVector, 6);
vtkCxxSetObjectMacro(vtkPVRenderView, LastSelection, vtkSelection);
//----------------------------------------------------------------------------
vtkPVRenderView::vtkPVRenderView()
......@@ -138,11 +138,6 @@ vtkPVRenderView::vtkPVRenderView()
this->PreviousParallelProjectionStatus = 0;
this->NeedsOrderedCompositing = false;
this->LastComputedBounds[0] = this->LastComputedBounds[2] =
this->LastComputedBounds[4] = -1.0;
this->LastComputedBounds[1] = this->LastComputedBounds[3] =
this->LastComputedBounds[5] = 1.0;
this->SynchronizedRenderers = vtkPVSynchronizedRenderer::New();
if (this->SynchronizedWindows->GetLocalProcessIsDriver())
......@@ -584,58 +579,41 @@ void vtkPVRenderView::FinishSelection(vtkSelection* sel)
//----------------------------------------------------------------------------
void vtkPVRenderView::ResetCameraClippingRange()
{
//cout << "Clipping Bounds: "
// << this->LastComputedBounds[0] << ", "
// << this->LastComputedBounds[1] << ", "
// << this->LastComputedBounds[2] << ", "
// << this->LastComputedBounds[3] << ", "
// << this->LastComputedBounds[4] << ", "
// << this->LastComputedBounds[5] << endl;
this->GetRenderer()->ResetCameraClippingRange(this->LastComputedBounds);
this->GetNonCompositedRenderer()->ResetCameraClippingRange(this->LastComputedBounds);
if (this->GeometryBounds.IsValid())
{
double bounds[6];
this->GeometryBounds.GetBounds(bounds);
this->GetRenderer()->ResetCameraClippingRange(bounds);
this->GetNonCompositedRenderer()->ResetCameraClippingRange(bounds);
}
}
#define PRINT_BOUNDS(bds)\
bds[0] << "," << bds[1] << "," << bds[2] << "," << bds[3] << "," << bds[4] << "," << bds[5] << ","
//----------------------------------------------------------------------------
void vtkPVRenderView::GatherBoundsInformation(
bool using_distributed_rendering)
void vtkPVRenderView::SynchronizeGeometryBounds()
{
vtkMath::UninitializeBounds(this->LastComputedBounds);
if (this->GetLocalProcessDoesRendering(using_distributed_rendering))
double bounds[6];
vtkMath::UninitializeBounds(bounds);
if (this->GeometryBounds.IsValid())
{
this->CenterAxes->SetUseBounds(0);
// if ComputeVisiblePropBounds is called when there's no real window on the
// local process, all vtkWidgetRepresentations return wacky Z bounds which
// screws up the renderer and we don't see any images.
this->GetRenderer()->ComputeVisiblePropBounds(this->LastComputedBounds);
this->CenterAxes->SetUseBounds(1);
this->GeometryBounds.GetBounds(bounds);
}
if (using_distributed_rendering)
{
// sync up bounds across all processes when doing distributed rendering.
this->SynchronizedWindows->SynchronizeBounds(this->LastComputedBounds);
}
this->SynchronizedWindows->SynchronizeBounds(bounds);
if (!vtkMath::AreBoundsInitialized(this->LastComputedBounds))
if (!vtkMath::AreBoundsInitialized(bounds))
{
this->GeometryBounds.SetBounds(-1, 1, -1, 1, -1, 1);
}
else
{
this->LastComputedBounds[0] = this->LastComputedBounds[2] =
this->LastComputedBounds[4] = -1.0;
this->LastComputedBounds[1] = this->LastComputedBounds[3] =
this->LastComputedBounds[5] = 1.0;
this->GeometryBounds.SetBounds(bounds);
}
//cout << "Bounds: "
// << this->LastComputedBounds[0] << ", "
// << this->LastComputedBounds[1] << ", "
// << this->LastComputedBounds[2] << ", "
// << this->LastComputedBounds[3] << ", "
// << this->LastComputedBounds[4] << ", "
// << this->LastComputedBounds[5] << endl;
this->UpdateCenterAxes();
this->ResetCameraClippingRange();
}
......@@ -671,7 +649,9 @@ void vtkPVRenderView::ResetCamera()
// Remember, vtkRenderer::ResetCamera() calls
// vtkRenderer::ResetCameraClippingPlanes() with the given bounds.
this->RenderView->GetRenderer()->ResetCamera(this->LastComputedBounds);
double bounds[6];
this->GeometryBounds.GetBounds(bounds);
this->RenderView->GetRenderer()->ResetCamera(bounds);
this->InvokeEvent(vtkCommand::ResetCameraEvent);
}
......@@ -745,6 +725,10 @@ void vtkPVRenderView::Update()
{
vtkTimerLog::MarkStartEvent("RenderView::Update");
// reset the bounds, so that representations can provide us with bounds
// information during update.
this->GeometryBounds.Reset();
this->RequestInformation->Set(REPRESENTED_DATA_STORE(),
this->Internals->GeometryStore.GetPointer());
......@@ -800,6 +784,9 @@ void vtkPVRenderView::Update()
this->InteractiveRenderProcesses = vtkPVSession::CLIENT_AND_SERVERS;
}
// Synchronize data bounds.
this->SynchronizeGeometryBounds();
vtkTimerLog::MarkEndEvent("RenderView::Update");
}
......@@ -901,17 +888,6 @@ void vtkPVRenderView::Render(bool interactive, bool skip_rendering)
this->InteractiveRenderImageReductionFactor :
this->StillRenderImageReductionFactor));
if (!interactive)
{
// Keep bounds information up-to-date.
// GatherBoundsInformation will not do communication unless using
// distributed rendering.
this->GatherBoundsInformation(
in_cave_mode || use_distributed_rendering);
this->UpdateCenterAxes(this->LastComputedBounds);
}
this->UsedLODForLastRender = use_lod_rendering;
if (skip_rendering)
......@@ -1091,6 +1067,45 @@ void vtkPVRenderView::SetDeliverLODToAllProcesses(vtkInformation* info,
storage->SetDeliverToAllProcesses(repr, clone, true);
}
//----------------------------------------------------------------------------
void vtkPVRenderView::SetGeometryBounds(vtkInformation* info,
double bounds[6], vtkMatrix4x4* matrix /*=NULL*/)
{
// FIXME: I need a cleaner way for accessing the render view.
vtkRepresentedDataStorage* storage =
vtkRepresentedDataStorage::SafeDownCast(
info->Get(REPRESENTED_DATA_STORE()));
if (!storage)
{
vtkGenericWarningMacro("Missing REPRESENTED_DATA_STORE().");
return;
}
vtkPVRenderView* self = vtkPVRenderView::SafeDownCast(storage->GetView());
if (self)
{
if (matrix && vtkMath::AreBoundsInitialized(bounds))
{
double min_point[4] = {bounds[0], bounds[2], bounds[4], 1};
double max_point[4] = {bounds[1], bounds[3], bounds[5], 1};
matrix->MultiplyPoint(min_point, min_point);
matrix->MultiplyPoint(max_point, max_point);
double transformed_bounds[6];
transformed_bounds[0] = min_point[0] / min_point[3];
transformed_bounds[2] = min_point[1] / min_point[3];
transformed_bounds[4] = min_point[2] / min_point[3];
transformed_bounds[1] = max_point[0] / max_point[3];
transformed_bounds[3] = max_point[1] / max_point[3];
transformed_bounds[5] = max_point[2] / max_point[3];
self->GeometryBounds.AddBounds(transformed_bounds);
}
else
{
self->GeometryBounds.AddBounds(bounds);
}
}
}
//----------------------------------------------------------------------------
bool vtkPVRenderView::ShouldUseDistributedRendering(double geometry_size)
{
......@@ -1203,9 +1218,10 @@ void vtkPVRenderView::RemovePropFromRenderer(vtkProp* prop)
}
//----------------------------------------------------------------------------
void vtkPVRenderView::UpdateCenterAxes(double bounds[6])
void vtkPVRenderView::UpdateCenterAxes()
{
vtkBoundingBox bbox(bounds);
vtkBoundingBox bbox(this->GeometryBounds);
// include the center of rotation in the axes size determination.
bbox.AddPoint(this->CenterAxes->GetPosition());
......
......@@ -36,6 +36,7 @@
#define __vtkPVRenderView_h
#include "vtkPVView.h"
#include "vtkBoundingBox.h" // needed for iVar
class vtkAlgorithmOutput;
class vtkCamera;
......@@ -49,6 +50,7 @@ class vtkInteractorStyleRubberBand3D;
class vtkInteractorStyleRubberBandZoom;
class vtkLight;
class vtkLightKit;
class vtkMatrix4x4;
class vtkProp;
class vtkPVAxesWidget;
class vtkPVCenterAxesActor;
......@@ -243,17 +245,6 @@ public:
// processes.
static vtkInformationObjectBaseKey* REPRESENTED_DATA_STORE();
// Description:
// vtkDataRepresentation can use this key to publish meta-data about geometry
// bounds in the vtkPVView::REQUEST_UPDATE().
// If this meta-data is available, then the view can make informed
// decisions when resetting camera to the bounds of visible data.
// If no bounds are specified by a representation then the data bounds are
// used, if possible.
// Note that all process don't have to report bounds. The view takes care of
// consolidating the bounds between all views.
static vtkInformationDoubleVectorKey* GEOMETRY_BOUNDS();
// Description:
// USE_LOD indicates if LOD is being used for the current render/update.
static vtkInformationIntegerKey* USE_LOD();
......@@ -351,6 +342,8 @@ public:
vtkInformation* info, vtkPVDataRepresentation* repr, bool clone);
static void MarkAsRedistributable(
vtkInformation* info, vtkPVDataRepresentation* repr);
static void SetGeometryBounds(vtkInformation* info,
double bounds[6], vtkMatrix4x4* transform = NULL);
public:
//*****************************************************************
......@@ -537,7 +530,7 @@ protected:
// Description:
// Synchronizes bounds information on all nodes.
// @CallOnAllProcessess
void GatherBoundsInformation(bool using_remote_rendering);
void SynchronizeGeometryBounds();
// Description:
// Set the last selection object.
......@@ -546,7 +539,7 @@ protected:
// Description:
// UpdateCenterAxes().
// Updates CenterAxes's scale and position.
void UpdateCenterAxes(double bounds[6]);
void UpdateCenterAxes();
// Description
// Returns true if the local process is doing to do actual render or
......@@ -585,7 +578,8 @@ protected:
double RemoteRenderingThreshold;
double LODRenderingThreshold;
double ClientOutlineThreshold;
double LastComputedBounds[6];
vtkBoundingBox GeometryBounds;
bool UseOffscreenRendering;
bool UseOffscreenRenderingForScreenshots;
bool UseInteractiveRenderingForSceenshots;
......
......@@ -49,6 +49,12 @@ void vtkRepresentedDataStorage::SetView(vtkPVRenderView* view)
this->View = view;
}
//----------------------------------------------------------------------------
vtkPVRenderView* vtkRepresentedDataStorage::GetView()
{
return this->View;
}
//----------------------------------------------------------------------------
unsigned long vtkRepresentedDataStorage::GetVisibleDataSize(bool low_res)
{
......
......@@ -67,6 +67,7 @@ public:
void Deliver(int use_low_res, unsigned int size, unsigned int *keys);
void SetView(vtkPVRenderView*);
vtkPVRenderView* GetView();
// Description:
// Render-view specific API to mark a piece as "re-distributable" i.e. it
......
......@@ -15,14 +15,17 @@
#include "vtkUnstructuredGridVolumeRepresentation.h"
#include "vtkCommand.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMatrix4x4.h"
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPolyDataMapper.h"
#include "vtkProjectedTetrahedraMapper.h"
#include "vtkPVGeometryFilter.h"
#include "vtkPVCacheKeeper.h"
#include "vtkPVGeometryFilter.h"
#include "vtkPVLODVolume.h"
#include "vtkPVRenderView.h"
#include "vtkPVUpdateSuppressor.h"
......@@ -194,6 +197,17 @@ int vtkUnstructuredGridVolumeRepresentation::ProcessViewRequest(
vtkPVRenderView::SetPiece(inInfo, this,
this->CacheKeeper->GetOutputDataObject(0));
vtkPVRenderView::MarkAsRedistributable(inInfo, this);
vtkDataSet* dataset = vtkDataSet::SafeDownCast(
this->CacheKeeper->GetOutputDataObject(0));
if (dataset)
{
vtkNew<vtkMatrix4x4> matrix;
this->Actor->GetMatrix(matrix.GetPointer());
vtkPVRenderView::SetGeometryBounds(inInfo, dataset->GetBounds(),
matrix.GetPointer());
}
}
else if (request_type == vtkPVView::REQUEST_UPDATE_LOD())
{
......
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