Skip to content

Commit e6d5bdd

Browse files
committed
using GA_FOR_ALL_PTOFF to iterate over points
1 parent d852bc4 commit e6d5bdd

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

Plugins/Houdini/aaOceanSOP.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include <SYS/SYS_Math.h>
1818
#include <UT/UT_DSOVersion.h>
1919
#include <UT/UT_Interrupt.h>
20-
#include <UT/UT_Matrix3.h>
21-
#include <UT/UT_Matrix4.h>
22-
#include <UT/UT_ThreadedAlgorithm.h>
2320
#include <GU/GU_Detail.h>
2421
#include <GU/GU_PrimPoly.h>
2522
#include <PRM/PRM_Include.h>
@@ -28,9 +25,6 @@
2825
#include <SOP/SOP_Guide.h>
2926
#include <UT/UT_Options.h>
3027
#include <GEO/GEO_AttributeHandle.h>
31-
#include <OP/OP_Operator.h>
32-
#include <OP/OP_OperatorTable.h>
33-
#include <PRM/PRM_Include.h>
3428

3529
void newSopOperator(OP_OperatorTable *table)
3630
{
@@ -301,20 +295,25 @@ OP_ERROR aaOceanSOP::cookMySop(OP_Context &context)
301295
spectrumHandle = GA_RWHandleF(spectrumRef.getAttribute());
302296
}
303297

304-
//#pragma omp parallel for
305-
for (size_t pt_index = 0; pt_index < gdp->getNumPoints(); ++pt_index)
298+
GA_Offset pt_offset;
299+
GA_FOR_ALL_PTOFF(gdp, pt_offset)
306300
{
307-
UT_Vector3F pos = gdp->getPos3(pt_index);
301+
UT_Vector3F pos = gdp->getPos3(pt_offset);
308302
UT_Vector3F uv;
309303

310304
if(isVertexContext)
311305
{
312306
// convert from Point to Vertex context
313-
GA_Offset vtx_index = gdp->pointVertex(pt_index);
307+
GA_Offset vtx_index = gdp->pointVertex(pt_offset);
308+
if(vtx_index == GA_INVALID_OFFSET)
309+
{
310+
std::cout << "invalid vtx_index. skipping point transfromation for pt index " << pt_offset << "\n";
311+
continue;
312+
}
314313
uv = UVHandle.get(vtx_index);
315314
}
316315
else
317-
uv = UVHandle.get(pt_index);
316+
uv = UVHandle.get(pt_offset);
318317

319318
const float u = uv.x();
320319
const float v = uv.y();
@@ -327,7 +326,7 @@ OP_ERROR aaOceanSOP::cookMySop(OP_Context &context)
327326
pos.z() += pOcean->getOceanData(u, v, aaOcean::eCHOPZ);
328327
}
329328

330-
gdp->setPos3(pt_index, pos); // not thread-safe
329+
gdp->setPos3(pt_offset, pos); // not thread-safe
331330

332331
if(enableEigens)
333332
{
@@ -342,14 +341,14 @@ OP_ERROR aaOceanSOP::cookMySop(OP_Context &context)
342341
eigenVectorMinusValue.y() = 0.0f;
343342
eigenVectorMinusValue.z() = pOcean->getOceanData(u, v, aaOcean::eEIGENMINUSZ);
344343

345-
eVecPlusHandle.set(pt_index, eigenVectorPlusValue);
346-
eVecMinusHandle.set(pt_index, eigenVectorMinusValue);
344+
eVecPlusHandle.set(pt_offset, eigenVectorPlusValue);
345+
eVecMinusHandle.set(pt_offset, eigenVectorMinusValue);
347346

348347
float eigenValue = pOcean->getOceanData(u, v, aaOcean::eFOAM);
349-
eValuesHandle.set(pt_index,eigenValue);
348+
eValuesHandle.set(pt_offset,eigenValue);
350349

351350
float spectrumValue = pOcean->getOceanData(u, v, aaOcean::eSPECTRUM);
352-
spectrumHandle.set(pt_index, spectrumValue);
351+
spectrumHandle.set(pt_offset, spectrumValue);
353352
}
354353
}
355354
unlockInputs();

0 commit comments

Comments
 (0)