Commit 8ff63775 authored by Sebastien Jourdain's avatar Sebastien Jourdain

Fix id management for representation delivery

Change-Id: If6181d6753312ebc7148d163e91dd0d18c8f02b3
parent 5f490998
......@@ -77,6 +77,9 @@ void vtkCompositeRepresentation::AddRepresentation(
{
assert(repr != NULL && key != NULL);
// Make sure the representation that we register is already initialized
repr->Initialize(1,0); // Should abort if no initialized as 1 > 0
if (this->Internals->Representations.find(key) !=
this->Internals->Representations.end())
{
......
......@@ -370,3 +370,13 @@ vtkDataObject* vtkCompositeSliceRepresentation::GetRenderedDataObject(int vtkNot
{
return this->InternalSliceFilter->GetInputDataObject(0,0);
}
//----------------------------------------------------------------------------
unsigned int vtkCompositeSliceRepresentation::Initialize(unsigned int minIdAvailable,
unsigned int maxIdAvailable)
{
unsigned int newMin =
this->OutlineRepresentation->Initialize(minIdAvailable, maxIdAvailable);
return this->Superclass::Initialize(newMin, maxIdAvailable);
}
......@@ -72,6 +72,11 @@ public:
// Override to provide input array name regardless if any slice cut the actual data.
virtual vtkDataObject* GetRenderedDataObject(int port);
// Description:
// Override because of internal composite representations that need to be
// initilized as well.
virtual unsigned int Initialize(unsigned int minIdAvailable, unsigned int maxIdAvailable);
//BTX
protected:
vtkCompositeSliceRepresentation();
......
......@@ -235,3 +235,13 @@ void vtkPVCompositeRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
unsigned int vtkPVCompositeRepresentation::Initialize(unsigned int minIdAvailable,
unsigned int maxIdAvailable)
{
unsigned int minId = minIdAvailable;
minId = this->CubeAxesRepresentation->Initialize(minId, maxIdAvailable);
minId = this->SelectionRepresentation->Initialize(minId, maxIdAvailable);
return this->Superclass::Initialize(minId, maxIdAvailable);
}
......@@ -79,6 +79,11 @@ public:
virtual void SetPointFieldDataArrayName(const char*);
virtual void SetCellFieldDataArrayName(const char*);
// Description:
// Override because of internal composite representations that need to be
// initilized as well.
virtual unsigned int Initialize(unsigned int minIdAvailable, unsigned int maxIdAvailable);
//BTX
protected:
vtkPVCompositeRepresentation();
......
......@@ -182,16 +182,7 @@ public:
vtkItem* GetItem(vtkPVDataRepresentation* repr, bool use_second)
{
RepresentationToIdMapType::iterator iter =
this->RepresentationToIdMap.find(repr);
if (iter != this->RepresentationToIdMap.end())
{
unsigned int index = iter->second;
return use_second? &(this->ItemsMap[index].second) :
&(this->ItemsMap[index].first);
}
return NULL;
return this->GetItem(repr->GetUniqueIdentifier(), use_second);
}
unsigned long GetVisibleDataSize(bool use_second_if_available)
......@@ -212,10 +203,6 @@ public:
return size;
}
typedef std::map<vtkPVDataRepresentation*, unsigned int>
RepresentationToIdMapType;
RepresentationToIdMapType RepresentationToIdMap;
ItemsMapType ItemsMap;
};
//*****************************************************************************
......@@ -349,47 +336,25 @@ unsigned long vtkPVDataDeliveryManager::GetVisibleDataSize(bool low_res)
}
//----------------------------------------------------------------------------
void vtkPVDataDeliveryManager::RegisterRepresentation(
unsigned int id, vtkPVDataRepresentation* repr)
void vtkPVDataDeliveryManager::RegisterRepresentation(vtkPVDataRepresentation* repr)
{
this->Internals->RepresentationToIdMap[repr] = id;
assert( "A representation must have a valid UniqueIdentifier"
&& repr->GetUniqueIdentifier());
vtkInternals::vtkItem item;
item.Representation = repr;
this->Internals->ItemsMap[id].first = item;
this->Internals->ItemsMap[repr->GetUniqueIdentifier()].first = item;
vtkInternals::vtkItem item2;
item2.Representation = repr;
this->Internals->ItemsMap[id].second= item2;
this->Internals->ItemsMap[repr->GetUniqueIdentifier()].second= item2;
}
//----------------------------------------------------------------------------
void vtkPVDataDeliveryManager::UnRegisterRepresentation(
vtkPVDataRepresentation* repr)
{
vtkInternals::RepresentationToIdMapType::iterator iter =
this->Internals->RepresentationToIdMap.find(repr);
if (iter == this->Internals->RepresentationToIdMap.end())
{
vtkErrorMacro("Invalid argument.");
return;
}
this->Internals->ItemsMap.erase(iter->second);
this->Internals->RepresentationToIdMap.erase(iter);
}
//----------------------------------------------------------------------------
unsigned int vtkPVDataDeliveryManager::GetRepresentationId(
vtkPVDataRepresentation* repr)
{
vtkInternals::RepresentationToIdMapType::iterator iter =
this->Internals->RepresentationToIdMap.find(repr);
if (iter == this->Internals->RepresentationToIdMap.end())
{
vtkErrorMacro("Invalid argument.");
return 0;
}
return iter->second;
this->Internals->ItemsMap.erase(repr->GetUniqueIdentifier());
}
//----------------------------------------------------------------------------
......
......@@ -51,9 +51,8 @@ public:
// makes it possible for representations to communicate with the storage
// directly using a self pointer, while enables views on different processes
// to communicate information about representations using their unique ids.
void RegisterRepresentation(unsigned int id, vtkPVDataRepresentation*);
void RegisterRepresentation(vtkPVDataRepresentation *repr);
void UnRegisterRepresentation(vtkPVDataRepresentation*);
unsigned int GetRepresentationId(vtkPVDataRepresentation*);
vtkPVDataRepresentation* GetRepresentation(unsigned int);
// Description:
......
......@@ -48,6 +48,8 @@ vtkPVDataRepresentation::vtkPVDataRepresentation()
this->ForcedCacheKey = 0.0;
this->NeedUpdate = true;
this->UniqueIdentifier = 0;
}
//----------------------------------------------------------------------------
......@@ -79,6 +81,7 @@ vtkExecutive* vtkPVDataRepresentation::CreateDefaultExecutive()
int vtkPVDataRepresentation::ProcessViewRequest(
vtkInformationRequestKey* request, vtkInformation*, vtkInformation*)
{
assert("We must have an ID at that time" && this->UniqueIdentifier);
assert(this->GetExecutive()->IsA("vtkPVDataRepresentationPipeline"));
if (this->GetVisibility() == false)
{
......@@ -100,6 +103,20 @@ void vtkPVDataRepresentation::MarkModified()
this->NeedUpdate = true;
}
//----------------------------------------------------------------------------
unsigned int vtkPVDataRepresentation::Initialize(unsigned int minIdAvailable, unsigned int maxIdAvailable)
{
// Already initialized ?
if(this->UniqueIdentifier)
{
return minIdAvailable;
}
assert("Invalid Representation Id. Not enough reserved ids." && (maxIdAvailable >= minIdAvailable));
this->UniqueIdentifier = minIdAvailable;
return (1 + this->UniqueIdentifier);
}
//----------------------------------------------------------------------------
int vtkPVDataRepresentation::RequestData(vtkInformation*,
vtkInformationVector**, vtkInformationVector*)
......
......@@ -63,6 +63,25 @@ public:
// update-suppressor.
virtual void MarkModified();
// Description:
// Initialize the representation with an identifier range so each internal
// representation can own a unique ID.
// If a representation requires more IDs than the set of ids provided,
// the representation MUST complains by an error or abort explaining how many
// ids where expected so the number of reserved ids could be easily adjust.
// Unless noted otherwise, this method must be called before calling any
// other methods on this class.
// @CallOnAllProcessess
// Internally you can pick an id that follow that condition
// minIdAvailable <= id <= maxIdAvailable
// Return the minIdAvailable after initialization so that new range could be used
virtual unsigned int Initialize(unsigned int minIdAvailable, unsigned int maxIdAvailable);
// Description:
// Return 0 if the Initialize() method was not called otherwise a unique ID
// that will be shared across the processes for that same object.
unsigned int GetUniqueIdentifier() { return this->UniqueIdentifier; }
// Description:
// Get/Set the visibility for this representation. When the visibility of
// representation of false, all view passes are ignored.
......@@ -172,6 +191,7 @@ protected:
double UpdateTime;
bool UpdateTimeValid;
unsigned int UniqueIdentifier;
private:
vtkPVDataRepresentation(const vtkPVDataRepresentation&); // Not implemented
void operator=(const vtkPVDataRepresentation&); // Not implemented
......
......@@ -83,12 +83,8 @@ class vtkPVRenderView::vtkInternals
std::map<int, vtkWeakPointer<vtkPVDataRepresentation> > PropMap;
public:
unsigned int UniqueId;
vtkNew<vtkPVDataDeliveryManager> DeliveryManager;
vtkInternals() : UniqueId(1)
{
}
void RegisterSelectionProp(
int id, vtkProp*, vtkPVDataRepresentation* rep)
{
......@@ -384,8 +380,7 @@ void vtkPVRenderView::AddRepresentationInternal(vtkDataRepresentation* rep)
// We only increase that counter when widget are not involved as in
// collaboration mode only the master has the widget in its representation
this->SynchronizationCounter++;
unsigned int id = this->Internals->UniqueId++;
this->Internals->DeliveryManager->RegisterRepresentation(id, dataRep);
this->Internals->DeliveryManager->RegisterRepresentation(dataRep);
}
this->Superclass::AddRepresentationInternal(rep);
......
......@@ -279,3 +279,13 @@ void vtkSelectionRepresentation::SetCellFieldDataArrayName(const char* val)
{
this->LabelRepresentation->SetCellFieldDataArrayName(val);
}
//----------------------------------------------------------------------------
unsigned int vtkSelectionRepresentation::Initialize(unsigned int minIdAvailable,
unsigned int maxIdAvailable)
{
unsigned int minId = minIdAvailable;
minId = this->LabelRepresentation->Initialize(minId, maxIdAvailable);
minId = this->GeometryRepresentation->Initialize(minId, maxIdAvailable);
return this->Superclass::Initialize(minId, maxIdAvailable);
}
......@@ -92,6 +92,11 @@ public:
virtual void SetPointFieldDataArrayName(const char* val);
virtual void SetCellFieldDataArrayName(const char* val);
// Description:
// Override because of internal composite representations that need to be
// initilized as well.
virtual unsigned int Initialize(unsigned int minIdAvailable, unsigned int maxIdAvailable);
//BTX
protected:
vtkSelectionRepresentation();
......
......@@ -24,6 +24,8 @@
#include <assert.h>
#define MAX_NUMBER_OF_INTERNAL_REPRESENTATIONS 10
vtkStandardNewMacro(vtkSMRepresentationProxy);
//----------------------------------------------------------------------------
vtkSMRepresentationProxy::vtkSMRepresentationProxy()
......@@ -56,6 +58,16 @@ void vtkSMRepresentationProxy::CreateVTKObjects()
return;
}
// Initialize vtkPVDataRepresentation with a unique ID
vtkClientServerStream stream;
stream << vtkClientServerStream::Invoke
<< VTKOBJECT(this)
<< "Initialize"
<< static_cast<unsigned int>(this->GetGlobalID())
<< static_cast<unsigned int>(this->GetGlobalID() + MAX_NUMBER_OF_INTERNAL_REPRESENTATIONS)
<< vtkClientServerStream::End;
this->ExecuteStream(stream);
vtkObject::SafeDownCast(this->GetClientSideObject())->AddObserver(
vtkCommand::UpdateDataEvent,
this, &vtkSMRepresentationProxy::OnVTKRepresentationUpdated);
......@@ -279,3 +291,18 @@ void vtkSMRepresentationProxy::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//---------------------------------------------------------------------------
vtkTypeUInt32 vtkSMRepresentationProxy::GetGlobalID()
{
bool has_gid = this->HasGlobalID();
if (!has_gid && this->Session != NULL)
{
// reserve 1+MAX_NUMBER_OF_INTERNAL_REPRESENTATIONS contiguous IDs for the source proxies and possible extract
// selection proxies.
this->SetGlobalID(
this->GetSession()->GetNextChunkGlobalUniqueIdentifier(1 +
MAX_NUMBER_OF_INTERNAL_REPRESENTATIONS));
}
return this->GlobalID;
}
......@@ -56,6 +56,9 @@ public:
// Called after the view updates.
virtual void ViewUpdated(vtkSMProxy* view);
// Description:
// Overridden to reserve additional IDs for use by internal composite representation
virtual vtkTypeUInt32 GetGlobalID();
//BTX
protected:
vtkSMRepresentationProxy();
......
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