review: deep copy in temporal cache + refactor

- use deep copy by default in temporal cache
- refactor python testing
- refactor improvement in EnSight6Readers
- refactor changelog
This commit is contained in:
Julien Fausty 2022-09-21 19:22:40 +02:00
parent fb8b3ca98f
commit a9a798e98f
7 changed files with 64 additions and 42 deletions

View File

@ -1,8 +1,9 @@
# Renew internal ensight point cache to avoid shadowing
# Make temporal cache deep copy by default
Previously, the EnSight 6 readers' point caches were always reallocated in
place. This would interfere with things that might store pointers to certain
data downstream (like the temporal cache).
Previously, the `vtkTemporalDataSetCache` filter had trouble dealing with changes to data upstream
of the pipeline. For example, the EnSight 6 readers' point caches were always reallocated in place.
This interferes with things that might store pointers to certain data downstream (like the temporal
cache).
This fix adds a renewal mechanism to the internal point cache for the
EnSight 6 readers.
This fix makes the temporal cache deep copy data by default. It also makes the EnSight6 readers more
robust by renewing the internal point cache every time the points are read from the file.

View File

@ -497,21 +497,13 @@ void vtkTemporalDataSetCache::ReplaceCacheItem(
{
vtkTDSCMemkindRAII(this);
vtkDataObject* cachedData = input->NewInstance();
vtkCompositeDataSet* compositeCache = vtkCompositeDataSet::SafeDownCast(cachedData);
if (!(vtkDataObject::GetUsingMemkind() && !this->IsASource) && this->GetCacheInMemkind())
if (vtkDataObject::GetUsingMemkind() && !this->IsASource)
{
cachedData->DeepCopy(input);
cachedData->ShallowCopy(input);
}
else
{
if (compositeCache)
{
compositeCache->RecursiveShallowCopy(input);
}
else
{
cachedData->ShallowCopy(input);
}
cachedData->DeepCopy(input);
}
this->Cache[inTime] = std::pair<unsigned long, vtkDataObject*>(outputUpdateTime, cachedData);
}

View File

@ -7,7 +7,6 @@ VTK_DATA_ROOT = vtkGetDataRoot()
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.StereoCapableWindowOn()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
reader = vtk.vtkGenericEnSightReader()

View File

@ -57,7 +57,7 @@ vtkStandardNewMacro(vtkEnSight6BinaryReader);
vtkEnSight6BinaryReader::vtkEnSight6BinaryReader()
{
this->NumberOfUnstructuredPoints = 0;
this->UnstructuredPoints = vtkPoints::New();
this->UnstructuredPoints = nullptr;
this->UnstructuredNodeIds = nullptr;
this->BinaryIFile = nullptr;
@ -70,13 +70,7 @@ vtkEnSight6BinaryReader::vtkEnSight6BinaryReader()
//------------------------------------------------------------------------------
vtkEnSight6BinaryReader::~vtkEnSight6BinaryReader()
{
if (this->UnstructuredNodeIds)
{
this->UnstructuredNodeIds->Delete();
this->UnstructuredNodeIds = nullptr;
}
this->UnstructuredPoints->Delete();
this->UnstructuredPoints = nullptr;
this->CleanUpCache();
if (this->BinaryIFile)
{
@ -194,6 +188,8 @@ int vtkEnSight6BinaryReader::ReadGeometryFile(
this->ReadLine(line);
this->ReadLine(line);
this->CleanUpCache();
// Read the node id and element id lines.
this->ReadLine(line); // node id *
sscanf(line, " %*s %*s %s", subLine);
@ -231,10 +227,6 @@ int vtkEnSight6BinaryReader::ReadGeometryFile(
return 0;
}
if (this->UnstructuredPoints)
{
this->UnstructuredPoints->Delete();
}
this->UnstructuredPoints = vtkPoints::New();
this->UnstructuredPoints->SetNumberOfPoints(this->NumberOfUnstructuredPoints);
@ -2856,4 +2848,21 @@ void vtkEnSight6BinaryReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
void vtkEnSight6BinaryReader::CleanUpCache()
{
if (this->UnstructuredPoints)
{
this->NumberOfUnstructuredPoints = 0;
this->UnstructuredPoints->Delete();
this->UnstructuredPoints = nullptr;
}
if (this->UnstructuredNodeIds)
{
this->UnstructuredNodeIds->Delete();
this->UnstructuredNodeIds = nullptr;
}
}
VTK_ABI_NAMESPACE_END

View File

@ -177,6 +177,11 @@ protected:
int SkipUnstructuredGrid(char line[256]);
///@}
/**
* Clean up the internal cached data
*/
virtual void CleanUpCache();
// global list of points for the unstructured parts of the model
int NumberOfUnstructuredPoints;
vtkPoints* UnstructuredPoints;

View File

@ -40,20 +40,14 @@ vtkStandardNewMacro(vtkEnSight6Reader);
vtkEnSight6Reader::vtkEnSight6Reader()
{
this->NumberOfUnstructuredPoints = 0;
this->UnstructuredPoints = vtkPoints::New();
this->UnstructuredPoints = nullptr;
this->UnstructuredNodeIds = nullptr;
}
//------------------------------------------------------------------------------
vtkEnSight6Reader::~vtkEnSight6Reader()
{
if (this->UnstructuredNodeIds)
{
this->UnstructuredNodeIds->Delete();
this->UnstructuredNodeIds = nullptr;
}
this->UnstructuredPoints->Delete();
this->UnstructuredPoints = nullptr;
this->CleanUpCache();
}
//------------------------------------------------------------------------------
@ -244,6 +238,8 @@ int vtkEnSight6Reader::ReadGeometryFile(
// ReadNextDataLine because the description line could be blank.
this->ReadLine(line);
this->CleanUpCache();
// Read the node id and element id lines.
this->ReadLine(line);
sscanf(line, " %*s %*s %s", subLine);
@ -265,13 +261,11 @@ int vtkEnSight6Reader::ReadGeometryFile(
this->ReadNextDataLine(line); // "coordinates"
this->ReadNextDataLine(line);
this->NumberOfUnstructuredPoints = atoi(line);
if (this->UnstructuredPoints)
{
this->UnstructuredPoints->Delete();
}
this->UnstructuredPoints = vtkPoints::New();
this->UnstructuredPoints->Allocate(this->NumberOfUnstructuredPoints);
int* tmpIds = new int[this->NumberOfUnstructuredPoints];
int maxId = 0;
@ -2200,4 +2194,21 @@ void vtkEnSight6Reader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
void vtkEnSight6Reader::CleanUpCache()
{
if (this->UnstructuredPoints)
{
this->NumberOfUnstructuredPoints = 0;
this->UnstructuredPoints->Delete();
this->UnstructuredPoints = nullptr;
}
if (this->UnstructuredNodeIds)
{
this->UnstructuredNodeIds->Delete();
this->UnstructuredNodeIds = nullptr;
}
}
VTK_ABI_NAMESPACE_END

View File

@ -140,6 +140,11 @@ protected:
int CreateStructuredGridOutput(
int partId, char line[256], const char* name, vtkMultiBlockDataSet* output) override;
/**
* Clean up the internal cached data
*/
virtual void CleanUpCache();
// global list of points for the unstructured parts of the model
int NumberOfUnstructuredPoints;
vtkPoints* UnstructuredPoints;