Skip to content

Commit 4c64e08

Browse files
utkarshayachitkwrobot
authored andcommitted
Merge topic 'read-selected-halos-both-readers'
0d0a51a Remove space from property name 9337ed4 Add load only this halo option to multiblock genericio reader 78d892e Fixed loading data arrays when reading selected halos
2 parents abeac21 + 0d0a51a commit 4c64e08

File tree

5 files changed

+306
-37
lines changed

5 files changed

+306
-37
lines changed

ParaViewCore/VTKExtensions/CosmoTools/resources/GenericIOReader.xml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
</Documentation>
123123
</IntVectorProperty>
124124

125-
<StringVectorProperty name="Halo Id"
125+
<StringVectorProperty name="HaloId"
126126
command="SetHaloIdVariableName"
127127
number_of_elements="1"
128128
panel_visibility="advanced">
@@ -254,6 +254,40 @@
254254
</Documentation>
255255
</IntVectorProperty>
256256

257+
<StringVectorProperty name="HaloId"
258+
command="SetHaloIdVariableName"
259+
number_of_elements="1"
260+
panel_visibility="advanced">
261+
<StringListDomain name="array_list">
262+
<RequiredProperties>
263+
<Property function="ArrayList" name="PointArrayListInfo" />
264+
</RequiredProperties>
265+
</StringListDomain>
266+
<Documentation>
267+
Which data array in the file contains the halo ids. This is used with
268+
the halo ids to load to determine which points to load.
269+
</Documentation>
270+
</StringVectorProperty>
271+
272+
273+
<IntVectorProperty
274+
name="HalosToLoad"
275+
command="SetRequestedHaloId"
276+
label="Halos To Load"
277+
number_of_elements="0"
278+
number_of_elements_per_command="1"
279+
repeat_command="1"
280+
set_number_command="SetNumberOfRequestedHaloIds"
281+
use_index="1"
282+
panel_visibility="advanced" >
283+
<Documentation>
284+
Only load in points with these halo ids from the file.
285+
If no halo ids are specified, load all the points.
286+
</Documentation>
287+
<IntRangeDomain min="0" name="range" />
288+
</IntVectorProperty>
289+
290+
257291
</SourceProxy>
258292

259293
</ProxyGroup>
@@ -284,7 +318,7 @@
284318
<Property name="zAxis" />
285319
<Property name="QueryRankNeighbors" />
286320
<Property name="RankInQuery" />
287-
<Property name="Halo Id" />
321+
<Property name="HaloId" />
288322
<Property name="HalosToLoad" />
289323
</ExposedProperties>
290324
</SubProxy>
@@ -342,6 +376,8 @@
342376
<Property name="zAxis" />
343377
<Property name="ReadMethod"/>
344378
<Property name="BlockAssignmentStrategy"/>
379+
<Property name="HaloId" />
380+
<Property name="HalosToLoad" />
345381
</ExposedProperties>
346382
</SubProxy>
347383
<StringVectorProperty command="GetCurrentFileName"

ParaViewCore/VTKExtensions/CosmoTools/vtkPGenericIOMultiBlockReader.cxx

Lines changed: 134 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*=========================================================================
22
33
Program: Visualization Toolkit
4-
Module: vtkPGenericIOReader.cxx
4+
Module: vtkPGenericIOMultiBlockReader.cxx
55
66
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
77
All rights reserved.
@@ -20,6 +20,7 @@
2020
#include "vtkCompositeDataPipeline.h"
2121
#include "vtkDataArraySelection.h"
2222
#include "vtkGenericIOUtilities.h"
23+
#include "vtkIdList.h"
2324
#include "vtkInformation.h"
2425
#include "vtkInformationKey.h"
2526
#include "vtkInformationDoubleKey.h"
@@ -181,6 +182,7 @@ vtkPGenericIOMultiBlockReader::vtkPGenericIOMultiBlockReader()
181182
this->XAxisVariableName = NULL;
182183
this->YAxisVariableName = NULL;
183184
this->ZAxisVariableName = NULL;
185+
this->HaloIdVariableName = NULL;
184186
this->GenericIOType = IOTYPEMPI;
185187
this->BlockAssignment = ROUND_ROBIN;
186188
this->BuildMetaData = false;
@@ -194,6 +196,7 @@ vtkPGenericIOMultiBlockReader::vtkPGenericIOMultiBlockReader()
194196

195197
this->ArrayList = vtkStringArray::New();
196198
this->PointDataArraySelection = vtkDataArraySelection::New();
199+
this->HaloList = vtkIdList::New();
197200
this->SelectionObserver = vtkCallbackCommand::New();
198201
this->SelectionObserver->SetCallback(
199202
&vtkPGenericIOMultiBlockReader::SelectionModifiedCallback);
@@ -215,6 +218,7 @@ vtkPGenericIOMultiBlockReader::~vtkPGenericIOMultiBlockReader()
215218
vtkGenericIOUtilities::SafeDeleteString(this->XAxisVariableName);
216219
vtkGenericIOUtilities::SafeDeleteString(this->YAxisVariableName);
217220
vtkGenericIOUtilities::SafeDeleteString(this->ZAxisVariableName);
221+
vtkGenericIOUtilities::SafeDeleteString(this->HaloIdVariableName);
218222

219223
if (this->MetaData != NULL)
220224
{
@@ -223,6 +227,7 @@ vtkPGenericIOMultiBlockReader::~vtkPGenericIOMultiBlockReader()
223227

224228
this->ArrayList->Delete();
225229
this->PointDataArraySelection->RemoveObserver(this->SelectionObserver);
230+
this->HaloList->Delete();
226231
this->SelectionObserver->Delete();
227232
this->PointDataArraySelection->Delete();
228233

@@ -289,6 +294,47 @@ void vtkPGenericIOMultiBlockReader::SetPointArrayStatus(
289294
}
290295
}
291296

297+
//------------------------------------------------------------------------------
298+
vtkIdType vtkPGenericIOMultiBlockReader::GetRequestedHaloId(vtkIdType i)
299+
{
300+
assert("pre: array index out of bounds" &&
301+
(i >= 0 && this->HaloList->GetNumberOfIds() > i));
302+
return this->HaloList->GetId(i);
303+
}
304+
305+
//------------------------------------------------------------------------------
306+
vtkIdType vtkPGenericIOMultiBlockReader::GetNumberOfRequestedHaloIds()
307+
{
308+
return this->HaloList->GetNumberOfIds();
309+
}
310+
311+
//------------------------------------------------------------------------------
312+
void vtkPGenericIOMultiBlockReader::SetNumberOfRequestedHaloIds(vtkIdType numIds)
313+
{
314+
this->HaloList->SetNumberOfIds(numIds);
315+
this->Modified();
316+
}
317+
318+
//------------------------------------------------------------------------------
319+
void vtkPGenericIOMultiBlockReader::AddRequestedHaloId(vtkIdType haloId)
320+
{
321+
this->SetRequestedHaloId(this->GetNumberOfRequestedHaloIds(),haloId);
322+
}
323+
324+
//------------------------------------------------------------------------------
325+
void vtkPGenericIOMultiBlockReader::ClearRequestedHaloIds()
326+
{
327+
this->HaloList->Reset();
328+
this->Modified();
329+
}
330+
331+
//------------------------------------------------------------------------------
332+
void vtkPGenericIOMultiBlockReader::SetRequestedHaloId(vtkIdType i, vtkIdType haloId)
333+
{
334+
*this->HaloList->WritePointer(i,1) = haloId;
335+
this->Modified();
336+
}
337+
292338
//------------------------------------------------------------------------------
293339
bool vtkPGenericIOMultiBlockReader::ReaderParametersChanged()
294340
{
@@ -596,6 +642,13 @@ void vtkPGenericIOMultiBlockReader::LoadRawDataForBlock(int blockId)
596642
this->LoadRawVariableDataForBlock( yaxis, blockId );
597643
this->LoadRawVariableDataForBlock( zaxis, blockId );
598644

645+
if (this->HaloList->GetNumberOfIds() > 0)
646+
{
647+
std::string haloIds = std::string(this->HaloIdVariableName);
648+
haloIds = vtkGenericIOUtilities::trim(haloIds);
649+
this->LoadRawVariableDataForBlock(haloIds,blockId);
650+
}
651+
599652
#ifdef DEBUG
600653
std::cout << "\t==========\n";
601654
std::cout << "\tNUMBER OF ARRAYS: "
@@ -660,8 +713,9 @@ void vtkPGenericIOMultiBlockReader::GetPointFromRawData(
660713
}
661714

662715
//------------------------------------------------------------------------------
663-
void vtkPGenericIOMultiBlockReader::LoadCoordinatesForBlock(vtkUnstructuredGrid *grid,
664-
int blockId)
716+
void vtkPGenericIOMultiBlockReader::LoadCoordinatesForBlock(
717+
vtkUnstructuredGrid *grid, std::set< vtkIdType >& pointsInSelectedHalos,
718+
int blockId)
665719
{
666720
assert("pre: metadata is NULL!" && (this->MetaData != NULL));
667721
assert("pre: grid is NULL!" && (grid != NULL) );
@@ -708,13 +762,45 @@ void vtkPGenericIOMultiBlockReader::LoadCoordinatesForBlock(vtkUnstructuredGrid
708762

709763
double pnt[3];
710764
vtkIdType idx = 0;
711-
for( ;idx < nparticles; ++idx)
765+
if (this->HaloList->GetNumberOfIds() == 0)
712766
{
713-
this->GetPointFromRawData(xType, xBuffer, yType, yBuffer, zType, zBuffer,
714-
idx, pnt);
715-
pnts->SetPoint(idx,pnt);
716-
cells->InsertNextCell(1,&idx);
717-
} // END for all points
767+
for( ;idx < nparticles; ++idx)
768+
{
769+
this->GetPointFromRawData(xType, xBuffer, yType, yBuffer, zType, zBuffer,
770+
idx, pnt);
771+
pnts->SetPoint(idx,pnt);
772+
cells->InsertNextCell(1,&idx);
773+
} // END for all points
774+
}
775+
else
776+
{
777+
std::string haloVarName = std::string(this->HaloIdVariableName);
778+
haloVarName = vtkGenericIOUtilities::trim(haloVarName);
779+
int haloType = this->MetaData->VariableGenericIOType[haloVarName];
780+
void* haloBuffer = dataBlock.RawCache[haloVarName];
781+
for (vtkIdType i = 0; idx < nparticles; ++idx)
782+
{
783+
vtkIdType haloId = vtkGenericIOUtilities::GetIdFromRawBuffer(haloType,haloBuffer,idx);
784+
bool isInRequestedHalo = false;
785+
for (vtkIdType j = 0; j < this->GetNumberOfRequestedHaloIds(); ++j)
786+
{
787+
if (haloId == this->HaloList->GetId(j))
788+
{
789+
isInRequestedHalo = true;
790+
pointsInSelectedHalos.insert(idx);
791+
break;
792+
}
793+
}
794+
if (isInRequestedHalo)
795+
{
796+
this->GetPointFromRawData(xType,xBuffer,yType,yBuffer,zType,zBuffer,idx,pnt);
797+
pnts->SetPoint(i,pnt);
798+
cells->InsertNextCell(1,&i);
799+
++i;
800+
}
801+
}
802+
pnts->SetNumberOfPoints(pointsInSelectedHalos.size());
803+
}
718804

719805
grid->SetPoints(pnts);
720806

@@ -723,9 +809,25 @@ void vtkPGenericIOMultiBlockReader::LoadCoordinatesForBlock(vtkUnstructuredGrid
723809
grid->Squeeze();
724810
}
725811

812+
namespace {
813+
template< typename T >
814+
void GetOnlyDataInHalo(vtkDataArray* allData, vtkDataArray* haloData, std::set< vtkIdType > pointsInHalo)
815+
{
816+
T* data = (T*) allData->GetVoidPointer(0);
817+
T* filteredData = (T*) haloData->GetVoidPointer(0);
818+
vtkIdType i = 0;
819+
for (std::set< vtkIdType >::iterator itr = pointsInHalo.begin();
820+
itr != pointsInHalo.end(); ++itr)
821+
{
822+
filteredData[i++] = data[*itr];
823+
}
824+
}
825+
}
826+
726827
//------------------------------------------------------------------------------
727-
void vtkPGenericIOMultiBlockReader::LoadDataArraysForBlock(vtkUnstructuredGrid *grid,
728-
int blockId)
828+
void vtkPGenericIOMultiBlockReader::LoadDataArraysForBlock(
829+
vtkUnstructuredGrid *grid, const std::set< vtkIdType >& pointsInSelectedHalos,
830+
int blockId)
729831
{
730832
assert("pre: metadata is NULL!" && (this->MetaData != NULL));
731833
assert("pre: grid is NULL!" && (grid != NULL) );
@@ -734,8 +836,8 @@ void vtkPGenericIOMultiBlockReader::LoadDataArraysForBlock(vtkUnstructuredGrid *
734836

735837
block_t& dataBlock = this->MetaData->Blocks[blockId];
736838

737-
assert("pre: # points in dataset different from points in block" &&
738-
(static_cast<uint64_t>(grid->GetNumberOfPoints()) == dataBlock.NumberOfElements));
839+
// assert("pre: # points in dataset different from points in block" &&
840+
// (static_cast<uint64_t>(grid->GetNumberOfPoints()) == dataBlock.NumberOfElements));
739841
vtkPointData* PD = grid->GetPointData();
740842

741843
int arrayIdx = 0;
@@ -745,16 +847,29 @@ void vtkPGenericIOMultiBlockReader::LoadDataArraysForBlock(vtkUnstructuredGrid *
745847
if( this->PointDataArraySelection->ArrayIsEnabled(name) )
746848
{
747849
std::string varName( name );
748-
vtkDataArray *dataArray =
850+
vtkSmartPointer< vtkDataArray > dataArray;
851+
dataArray.TakeReference(
749852
vtkGenericIOUtilities::GetVtkDataArray(
750853
varName,
751854
this->MetaData->VariableGenericIOType[ varName ],
752855
dataBlock.RawCache[ varName ],
753856
dataBlock.NumberOfElements
754-
);
857+
));
858+
if (this->HaloList->GetNumberOfIds() != 0)
859+
{
860+
vtkSmartPointer< vtkDataArray > onlyDataInHalo;
861+
onlyDataInHalo.TakeReference(dataArray->NewInstance());
862+
onlyDataInHalo->SetNumberOfTuples(grid->GetNumberOfPoints());
863+
onlyDataInHalo->SetName(dataArray->GetName());
864+
switch (dataArray->GetDataType()) {
865+
vtkTemplateMacro(GetOnlyDataInHalo<VTK_TT>(
866+
dataArray,onlyDataInHalo,pointsInSelectedHalos));
867+
}
868+
dataArray = onlyDataInHalo;
869+
}
870+
755871

756872
PD->AddArray( dataArray );
757-
dataArray->Delete();
758873
} // END if the array is enabled
759874
} // END for all arrays
760875

@@ -771,12 +886,13 @@ vtkUnstructuredGrid* vtkPGenericIOMultiBlockReader::LoadBlock(int blockId)
771886
this->LoadRawDataForBlock(blockId);
772887

773888
vtkUnstructuredGrid* grid = vtkUnstructuredGrid::New();
889+
std::set< vtkIdType > pointsInSelectedHalos;
774890

775891
// STEP 2: Load coordinates
776-
this->LoadCoordinatesForBlock(grid,blockId);
892+
this->LoadCoordinatesForBlock(grid,pointsInSelectedHalos,blockId);
777893

778894
// STEP 3: Load data
779-
this->LoadDataArraysForBlock(grid,blockId);
895+
this->LoadDataArraysForBlock(grid,pointsInSelectedHalos,blockId);
780896

781897
if (this->Reader->IsSpatiallyDecomposed())
782898
{

0 commit comments

Comments
 (0)