예제 #1
0
/* ******************************************************************************
*  Function Name : instanceCube()
*
*  Description :
*
*  Input Arguments : GU_Detail *inst_gdp, GU_Detail *mb_gdp
*
*  Return Value : int
*
***************************************************************************** */
int VRAY_clusterThis::instanceCube(GU_Detail * inst_gdp, GU_Detail * mb_gdp)
{
#ifdef DEBUG
   std::cout << "VRAY_clusterThis::instanceCube()" << std::endl;
#endif

   GEO_Primitive * myCube;
   GEO_Point * ppt;
   UT_Matrix4 xform(1.0);
//   UT_XformOrder xformOrder(UT_XformOrder::TRS,  UT_XformOrder::XYZ);
   UT_Matrix3 rot_xform(1.0);
//   UT_Vector3 myDir = myPointAttributes.N;
   UT_Vector3 myUp = UT_Vector3(0,1,0);
   rot_xform.orient(myPointAttributes.N, myUp);
   xform = rot_xform;

   myCube = (GEO_Primitive *) inst_gdp->cube(
               myPointAttributes.myNewPos[0] - ((mySize[0] * myPointAttributes.pscale) / 2),
               myPointAttributes.myNewPos[0] + ((mySize[0] * myPointAttributes.pscale) / 2),
               myPointAttributes.myNewPos[1] - ((mySize[1] * myPointAttributes.pscale) / 2),
               myPointAttributes.myNewPos[1] + ((mySize[1] * myPointAttributes.pscale) / 2),
               myPointAttributes.myNewPos[2] - ((mySize[2] * myPointAttributes.pscale) / 2),
               myPointAttributes.myNewPos[2] + ((mySize[2] * myPointAttributes.pscale) / 2));

   for(int i=0; i < myCube->getVertexCount(); i++) {
         ppt = myCube->getVertexElement(i).getPt();
         UT_Vector4  P = ppt->getPos();
         P *= xform;
         ppt->setPos(P);
      }

   VRAY_clusterThis::setInstanceAttributes(myCube);

   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {

         myCube = (GEO_Primitive *) mb_gdp->cube(myPointAttributes.myMBPos[0] - ((mySize[0] * myPointAttributes.pscale) / 2),
                                                 myPointAttributes.myMBPos[0] + ((mySize[0] * myPointAttributes.pscale) / 2),
                                                 myPointAttributes.myMBPos[1] - ((mySize[1] * myPointAttributes.pscale) / 2),
                                                 myPointAttributes.myMBPos[1] + ((mySize[1] * myPointAttributes.pscale) / 2),
                                                 myPointAttributes.myMBPos[2] - ((mySize[2] * myPointAttributes.pscale) / 2),
                                                 myPointAttributes.myMBPos[2] + ((mySize[2] * myPointAttributes.pscale) / 2));

         for(int i=0; i < myCube->getVertexCount(); i++) {
               ppt = myCube->getVertexElement(i).getPt();
               UT_Vector4  P = ppt->getPos();
               P *= xform;
               ppt->setPos(P);
            }

         VRAY_clusterThis::setInstanceAttributes(myCube);
      }

   if(myCVEX_Exec)
      VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname, CLUSTER_CVEX_POINT);

   if(myCVEX_Exec_prim)
      VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

   return 0;
}
/* ******************************************************************************
*  Function Name : instanceFile()
*
*  Description :  Instance the geometry from a BGEO file
*
*  Input Arguments : GU_Detail *file_gdp, GU_Detail *inst_gdp, GU_Detail *mb_gdp
*
*  Return Value : int
*
***************************************************************************** */
int VRAY_clusterThis::instanceFile(GU_Detail * file_gdp, GU_Detail * inst_gdp, GU_Detail * mb_gdp)
{
#ifdef DEBUG
   std::cout << "VRAY_clusterThis::instanceFile()" << std::endl;
   cout << "VRAY_clusterThis::instanceFile() myPointAttributes.geo_fname: " << myPointAttributes.geo_fname << endl;
#endif

#define USE_POINT_FNAME 1

   GU_Detail null_gdp;
   UT_Matrix4 xform(1.0);
   UT_Matrix3 rot_xform(1.0);
//   UT_XformOrder xformOrder(UT_XformOrder::SRT,  UT_XformOrder::XYZ);

#ifdef USE_POINT_FNAME
   GU_Detail * file_geo_gdp;
   file_geo_gdp = VRAY_Procedural::allocateGeometry();
   if(!file_geo_gdp->load((const char *)myPointAttributes.geo_fname).success())
      throw VRAY_clusterThis_Exception("VRAY_clusterThis::instanceFile() Failed to load geometry file ", 1);
   GU_Detail temp_gdp(file_geo_gdp);
#else
   GU_Detail temp_gdp(file_gdp);
#endif

   UT_Vector3 myDir = myPointAttributes.N;
   UT_Vector3 myUp = UT_Vector3(0, 1, 0);

// Transform the geo to the new position
   rot_xform.orient(myDir, myUp);
   xform = rot_xform;

   xform.scale(mySize[0] * myPointAttributes.pscale, mySize[1] * myPointAttributes.pscale, mySize[2] * myPointAttributes.pscale);
//    xform.rotate(myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2], xformOrder);
   xform.translate(myPointAttributes.myNewPos[0], myPointAttributes.myNewPos[1], myPointAttributes.myNewPos[2]);
//   xform.xform(xformOrder, myPointAttributes.myNewPos[0], myPointAttributes.myNewPos[1], myPointAttributes.myNewPos[2],
//               myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2],
//               mySize[0], mySize[1], mySize[2]);

   temp_gdp.transform(xform);

//   GU_Detail theFileGDP(theFiles[myPointAttributes.lod][myPointAttributes.anim_frame]);
   addFileAttributeRefs(&temp_gdp);
   setFileAttributes(&temp_gdp);

   // Run CVEX function on this instance
   if(myCVEX_Exec)
      VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname, CLUSTER_CVEX_POINT);
   if(myCVEX_Exec_prim)
      VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

   inst_gdp->merge(temp_gdp);


   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
#ifdef USE_POINT_FNAME
         GU_Detail temp_gdp(file_geo_gdp);
#else
         GU_Detail temp_gdp(file_gdp);
#endif

         xform.identity();
         rot_xform.identity();
         rot_xform.orient(myDir, myUp);
         xform = rot_xform;

         xform.scale(mySize[0] * myPointAttributes.pscale, mySize[1] * myPointAttributes.pscale, mySize[2] * myPointAttributes.pscale);
//        xform.rotate(myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2], xformOrder);
         xform.translate(myPointAttributes.myMBPos[0], myPointAttributes.myMBPos[1], myPointAttributes.myMBPos[2]);
         //   xform.xform(xformOrder, myPointAttributes.myMBPos[0], myPointAttributes.myMBPos[1], myPointAttributes.myMBPos[2],
         //               myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2],
         //               mySize[0], mySize[1], mySize[2]);

         // Run CVEX function on this instance
         if(myCVEX_Exec)
            VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname, CLUSTER_CVEX_POINT);
         if(myCVEX_Exec_prim)
            VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

         temp_gdp.transform(xform);
         mb_gdp->merge(temp_gdp);
      }


#ifdef USE_POINT_FNAME
   VRAY_Procedural::freeGeometry(file_geo_gdp);
#endif

   return 0;
}
/* ******************************************************************************
*  Function Name : ReadRFSDCreateAnimGeo()
*
*
*  Input Arguments : OP_Context &context
*
*  Return Value : int
*
***************************************************************************** */
inline int SOP_RF_Import::ReadRFSDCreateAnimGeo(UT_Interrupt * boss)
{

   UT_XformOrder xformOrder(UT_XformOrder::SRT);
   UT_Matrix4 work_matrix;
   GEO_Point * ppt;

   try {

         // For each object in the SD file, read it's frame header and geometry
         for(int cur_object = 0; cur_object < myRFSDFile->myRF_SD_Header.num_objects; cur_object++) {

               // read the object's frame header data
               if(myRFSDFile->readSDObjFrameHdr())
                  throw SOP_RF_Import_Exception(canNotReadSDObjectFrameHeader, exceptionError);


#ifdef DEBUG
               std::cout << "obj_name_len: " << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_name_len << std::endl;
               std::cout << "Object Name: " << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_name << std::endl;
               std::cout << "Object Transform:" << std::endl;
               for(int i = 0; i < 12; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_world_xform[i] << "\t";
               std::cout << std::endl;
               std::cout << "Translation Vector: " << std::endl;
               for(int i = 0; i < 3; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_trans_vec[i] << "\t";
               std::cout << std::endl;
               std::cout << "Rotation Vector: " << std::endl;
               for(int i = 0; i < 3; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_rot_vec[i] << "\t";
               std::cout << std::endl;
               std::cout << "Scale Vector: " << std::endl;
               for(int i = 0; i < 3; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_scale_vec[i] << "\t";
               std::cout << std::endl;
               std::cout << "Pivot Position: " << std::endl;
               for(int i = 0; i < 3; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_pivot_pos[i] << "\t";
               std::cout << std::endl << std::endl;
               std::cout << "CG Position: " << std::endl;
               for(int i = 0; i < 3; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_pos[i] << "\t";
               std::cout << std::endl;
               std::cout << "CG Velocity: " << std::endl;
               for(int i = 0; i < 3; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_vel[i] << "\t";
               std::cout << std::endl;
               std::cout << "CG Rotation: " << std::endl;
               for(int i = 0; i < 3; i++)
                  std::cout << myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_rot[i] << "\t";
               std::cout << std::endl << std::endl;
#endif

               if(myGUIState.t_sd_cg) {
                     work_matrix.identity();
                     work_matrix.xform(xformOrder,
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_trans_vec[0],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_trans_vec[1],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_trans_vec[2],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_rot_vec[0],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_rot_vec[1],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_rot_vec[2],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_scale_vec[0],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_scale_vec[1],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_scale_vec[2],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_pivot_pos[0],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_pivot_pos[1],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_pivot_pos[2]);
                     // Transform the geometry
                     gdp->transformPoints(work_matrix, (const GA_PointGroup *)objPrimitiveGrpList[cur_object]);
                  }

               if(myGUIState.t_sd_cg_xform) {
                     work_matrix.identity();
                     work_matrix.xform(xformOrder,
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_pos[0],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_pos[1],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_pos[2],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_rot[0],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_rot[1],
                                       myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_rot[2]);
                     // Transform the geometry
                     gdp->transformPoints(work_matrix, (const GA_PointGroup *)objPrimitiveGrpList[cur_object]);
                  }

#ifdef DEBUG
               std::cout << "Current primitive group: " << objPrimitiveGrpList[cur_object]->getName() << std::endl;
#endif

               GA_RWAttributeRef attrRef;
               GA_RWHandleI attrIntHandle;
               GA_RWHandleF attrFloatHandle;
               GA_RWHandleV3 attrVector3Handle;

               // If the user wants the CG data, add it to the geo detail
               if(myGUIState.t_sd_cg) {

                     if(myAttributeRefs.sd_CG_pos.isValid()) {
                           attrVector3Handle.bind(myAttributeRefs.sd_CG_pos.getAttribute());
                           attrVector3Handle.set(0, UT_Vector3(myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_pos));
                        }

                     if(myAttributeRefs.sd_CG_vel.isValid()) {
                           attrVector3Handle.bind(myAttributeRefs.sd_CG_vel.getAttribute());
                           attrVector3Handle.set(0, UT_Vector3(myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_vel));
                        }

                     if(myAttributeRefs.sd_CG_rot.isValid()) {
                           attrVector3Handle.bind(myAttributeRefs.sd_CG_rot.getAttribute());
                           attrVector3Handle.set(0, UT_Vector3(myRFSDFile->myRF_SD_Obj_Frame_Header.obj_CG_rot));
                        }

                  }


               // If vertex mode, update coordinates
               if(myRFSDFile->myRF_SD_Obj_Header.obj_mode) {

                     for(int cur_point = 0; cur_point < myRFSDFile->obj_detail[cur_object].num_points; cur_point++) {

#ifdef DEBUG
                           std::cout << "vertex number: " << cur_point + 1 << " of "
                                     << myRFSDFile->myRF_SD_Obj_Header.num_vertices
                                     << " vertices " << std::endl;
#endif

                           if(myRFSDFile->readSDFaceCoord())
                              throw SOP_RF_Import_Exception(canNotReadSDAnimFaceData, exceptionError);

#ifdef DEBUG
                           std::cout << "Vertex Coordinates: " << std::endl;
                           std::cout << myRFSDFile->myRF_SD_Face_Data.vertex[0] << "\t";
                           std::cout << myRFSDFile->myRF_SD_Face_Data.vertex[1] << "\t";
                           std::cout << myRFSDFile->myRF_SD_Face_Data.vertex[2] << std::endl;
#endif

                           // update points
                           if(boss->opInterrupt())
                              throw SOP_RF_Import_Exception(theSDAnimGeoCreationInterrupt, exceptionWarning);

                           myCurrPoint = cur_point;

                           // Get the current point to either update position
                           ppt = gdp->points().entry(cur_point);

                           if(ppt == NULL)
                              throw SOP_RF_Import_Exception(theSDAnimGeoCreationPointNULL, exceptionError);

#ifdef DEBUG
                           std::cout << "cur_object: " << cur_object << std::endl;
#endif

                           gdp->points()[cur_point]->setPos((float)myRFSDFile->myRF_SD_Face_Data.vertex[0],
                                                            (float)myRFSDFile->myRF_SD_Face_Data.vertex[1],
                                                            (float)myRFSDFile->myRF_SD_Face_Data.vertex[2], 1.0);

#ifdef DEBUG
                           std::cout << "position assigned" << std::endl;
#endif

                        } // for(int cur_point=0; ...
                  } // if(myRFSDFile->myRF_SD_Obj_Header.obj_mode)
            } // if vertex mode


      }
   catch(SOP_RF_Import_Exception e) {
         e.what();

         if(e.getSeverity() == exceptionWarning)
            addWarning(SOP_MESSAGE, errorMsgs[e.getErrorCode()]);
         else
            if(e.getSeverity() == exceptionError)
               addError(SOP_MESSAGE, errorMsgs[e.getErrorCode()]);

         if(myRFSDFile->SDifstream.is_open()) {
               myRFSDFile->closeSDFile(RF_FILE_READ);
            }

         return 1;
      }

   return 0;
}
예제 #4
0
/* ******************************************************************************
*  Function Name : instanceFile()
*
*  Description :  Instance the geometry from a BGEO file
*
*  Input Arguments : GU_Detail *file_gdp, GU_Detail *inst_gdp, GU_Detail *mb_gdp
*
*  Return Value : int
*
***************************************************************************** */
int VRAY_clusterThis::instanceFile(GU_Detail * file_gdp, GU_Detail * inst_gdp, GU_Detail * mb_gdp)
{
#ifdef DEBUG
   std::cout << "VRAY_clusterThis::instanceFile()" << std::endl;
#endif

   GU_Detail temp_gdp(file_gdp), null_gdp;
   UT_Matrix4 xform(1.0);
   UT_Matrix3 rot_xform(1.0);
//   UT_XformOrder xformOrder(UT_XformOrder::SRT,  UT_XformOrder::XYZ);

   UT_Vector3 myDir = myPointAttributes.N;
//   myDir.normalize();
   UT_Vector3 myUp = UT_Vector3(0,1,0);

// Transform the geo to the new position
   rot_xform.orient(myDir, myUp);
   xform = rot_xform;

   xform.scale(mySize[0] * myPointAttributes.pscale, mySize[1] * myPointAttributes.pscale, mySize[2] * myPointAttributes.pscale);
//    xform.rotate(myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2], xformOrder);
   xform.translate(myPointAttributes.myNewPos[0], myPointAttributes.myNewPos[1], myPointAttributes.myNewPos[2]);
//   xform.xform(xformOrder, myPointAttributes.myNewPos[0], myPointAttributes.myNewPos[1], myPointAttributes.myNewPos[2],
//               myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2],
//               mySize[0], mySize[1], mySize[2]);

   temp_gdp.transform(xform);

//   GU_Detail theFileGDP(theFiles[myPointAttributes.lod][myPointAttributes.anim_frame]);
   addFileAttributeOffsets(&temp_gdp);
   setFileAttributes(&temp_gdp);

   // Run CVEX function on this instance
   if(myCVEX_Exec)
      VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname, CLUSTER_CVEX_POINT);

   if(myCVEX_Exec_prim)
      VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

   inst_gdp->merge(temp_gdp);


   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
         GU_Detail temp_gdp(file_gdp);

         xform.identity();
         rot_xform.identity();
         rot_xform.orient(myDir, myUp);
         xform = rot_xform;

         xform.scale(mySize[0] * myPointAttributes.pscale, mySize[1] * myPointAttributes.pscale, mySize[2] * myPointAttributes.pscale);
//        xform.rotate(myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2], xformOrder);
         xform.translate(myPointAttributes.myMBPos[0], myPointAttributes.myMBPos[1], myPointAttributes.myMBPos[2]);
         //   xform.xform(xformOrder, myPointAttributes.myMBPos[0], myPointAttributes.myMBPos[1], myPointAttributes.myMBPos[2],
         //               myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2],
         //               mySize[0], mySize[1], mySize[2]);

         // Run CVEX function on this instance
         if(myCVEX_Exec)
            VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname, CLUSTER_CVEX_POINT);

         if(myCVEX_Exec_prim)
            VRAY_clusterThis::runCVEX(&temp_gdp, &null_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

         temp_gdp.transform(xform);
         mb_gdp->merge(temp_gdp);

      }

   return 0;
}
예제 #5
0
/* ******************************************************************************
*  Function Name : instanceGrid()
*
*  Description :
*
*  Input Arguments : GU_Detail *inst_gdp, GU_Detail *mb_gdp
*
*  Return Value : int
*
***************************************************************************** */
int VRAY_clusterThis::instanceGrid(GU_Detail * inst_gdp, GU_Detail * mb_gdp)
{
#ifdef DEBUG
   std::cout << "VRAY_clusterThis::instanceGrid()" << std::endl;
#endif

   GEO_Primitive * myGrid;
   GU_GridParms grid_parms;
   GEO_Point * ppt;
   UT_Matrix4 xform(1.0);
//   UT_XformOrder xformOrder(UT_XformOrder::TRS,  UT_XformOrder::XYZ);
   UT_Matrix3 rot_xform(1.0);
//   UT_Vector3 myDir = myPointAttributes.N;
   UT_Vector3 myUp = UT_Vector3(0,1,0);
   rot_xform.orient(myPointAttributes.N, myUp);
   xform = rot_xform;

   grid_parms.rows = 2;
   grid_parms.cols = 2;
   grid_parms.xsize = mySize[0] * myPointAttributes.pscale;
   grid_parms.ysize = mySize[1] * myPointAttributes.pscale;
   grid_parms.xcenter = myPointAttributes.myNewPos[0];
   grid_parms.ycenter = myPointAttributes.myNewPos[1];
   grid_parms.zcenter = myPointAttributes.myNewPos[2];
   grid_parms.plane = GU_PLANE_XY;
   myGrid = inst_gdp->buildGrid(grid_parms, GU_GRID_POLY);

   for(int i=0; i < myGrid->getVertexCount(); i++) {
         ppt = myGrid->getVertexElement(i).getPt();
         UT_Vector4  P = ppt->getPos();
         P *= xform;
         ppt->setPos(P);
      }

   VRAY_clusterThis::setInstanceAttributes(myGrid);

   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {

         grid_parms.xcenter = myPointAttributes.myMBPos[0];
         grid_parms.ycenter = myPointAttributes.myMBPos[1];
         grid_parms.zcenter = myPointAttributes.myMBPos[2];
         myGrid = mb_gdp->buildGrid(grid_parms, GU_GRID_POLY);

         for(int i=0; i < myGrid->getVertexCount(); i++) {
               ppt = myGrid->getVertexElement(i).getPt();
               UT_Vector4  P = ppt->getPos();
               P *= xform;
               ppt->setPos(P);
            }

         VRAY_clusterThis::setInstanceAttributes(myGrid);
      }

   if(myCVEX_Exec)
      VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname, CLUSTER_CVEX_POINT);

   if(myCVEX_Exec_prim)
      VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

   return 0;
}
    UT_Vector3 getScale(const GEO_Point &pt) const
	{ return myScale.isValid() ? pt.getValue<UT_Vector3>(myScale) : UT_Vector3(1, 1, 1); }
    UT_Vector3 getRotation(const GEO_Point &pt) const
	{ return myRot.isValid() ? M_PI / 180 * pt.getValue<UT_Vector3>(myRot) : UT_Vector3(0, 0, 0); }
    UT_Vector3 getPosition(const GEO_Point &pt) const
	{ return myPos.isValid() ? pt.getValue<UT_Vector3>(myPos) : UT_Vector3(0, 0, 0); }
예제 #9
0
/* ******************************************************************************
*  Function Name : render()
*
*  Description :   Render VRAY_clusterThis object
*
*  Input Arguments : None
*
*  Return Value : None
*
***************************************************************************** */
void VRAY_clusterThis::render()
{
   GU_Detail * gdp, *inst_gdp, *mb_gdp, *file_gdp;
   GEO_Point * ppt;

//   GEO_AttributeHandle attrHandleVelocity, attrHandleForce, attrHandleVorticity, attrHandleNormal, attrHandleNumNeighbors,
//   attrHandleTextureUV, attrHandleMass, attrHandleAge, attrHandleTemperature, attrHandleID,
//   attrHandleDensity, attrHandleViscosity, attrHandlePressure, attrHandlePscale;

   long int point_num = 0;
   static bool rendered = false;

   if(myVerbose > CLUSTER_MSG_QUIET) {
         std::cout << "VRAY_clusterThis::render() - Version: " << DCA_VERSION << std::endl;
         std::cout << "VRAY_clusterThis::render() - Built for Houdini Version: " << UT_MAJOR_VERSION
                   << "." << UT_MINOR_VERSION << "." << UT_BUILD_VERSION_INT << std::endl;
         std::cout << "VRAY_clusterThis::render() - Instancing ..." <<  endl;
      }


   try {

//          cout << "VM_GEO_clusterThis OTL version: " <<  myOTLVersion << endl;

//       if(myOTLVersion != DCA_VERSION) {
//          cout << "VM_GEO_clusterThis OTL is wrong version: " <<  myOTLVersion << ", should be version: " << DCA_VERSION << ", please install correct version." << endl;
//          throw VRAY_clusterThis_Exception ( "VRAY_clusterThis::render() VM_GEO_clusterThis OTL is wrong version!", 1 );
//       }


         if(!rendered || !myUseTempFile) {

               void * handle = VRAY_Procedural::queryObject(0);
               gdp = VRAY_Procedural::allocateGeometry();

               if(myUseGeoFile) {
                     // If the file failed to load, throw an exception
                     if(!(gdp->load((const char *)mySrcGeoFname).success()))
                        throw VRAY_clusterThis_Exception("VRAY_clusterThis::render() - Failed to read source geometry file ", 1);

                     if(myVerbose > CLUSTER_MSG_INFO)
                        cout << "VRAY_clusterThis::render() - Successfully loaded source geo file: " << mySrcGeoFname << endl;
                  }
               else {
                     gdp->copy(*VRAY_Procedural::queryGeometry(handle, 0));
                     if(myVerbose > CLUSTER_MSG_INFO)
                        cout << "VRAY_clusterThis::render() - Copied incoming geometry" << endl;
                  }


               gdp->getBBox(&myBox);

//               std::cout << "VRAY_clusterThis::render() - gdp->getBBox(&myBox): " << myBox << std::endl;

               VRAY_Procedural::querySurfaceShader(handle, myMaterial);
               myMaterial.harden();
//         myPointAttributes.material = myMaterial;

//         const char **        getSParm (int token) const
//         cout << "VRAY_clusterThis::render() getSParm: " << *getSParm (0) << endl;


#ifdef DEBUG
               cout << "VRAY_clusterThis::render() myMaterial: " << myMaterial << endl;
#endif

               myLOD = getLevelOfDetail(myBox);
               if(myVerbose > CLUSTER_MSG_INFO)
                  cout << "VRAY_clusterThis::render() myLOD: " << myLOD << endl;


               // Get the number if points of the incoming geometery, calculate an interval for reporting the status of the instancing to the user
               long int num_points = (long int) gdp->points().entries();
               long int stat_interval = (long int)(num_points * 0.10) + 1;

               if(myVerbose > CLUSTER_MSG_QUIET)
                  cout << "VRAY_clusterThis::render() Number of points of incoming geometry: " << num_points << endl;

               myObjectName = VRAY_Procedural::queryObjectName(handle);

//      cout << "VRAY_clusterThis::render() Object Name: " << myObjectName << endl;
//      cout << "VRAY_clusterThis::render() Root Name: " << queryRootName() << endl;

// DEBUG stuff ...

//   changeSetting("object:geo_velocityblur", "on");

               UT_String      str;
               int     vblur = 0;
               import("object:velocityblur", &vblur, 0);

               if(vblur) {
                     str = 0;
                     import("velocity", str);
                     if(str.isstring()) {
//               const char  *  name;
//               name = queryObjectName(handle);
                           VRAYwarning("%s[%s] cannot get %s",
                                       VRAY_Procedural::getClassName(), (const char *)myObjectName, " motion blur attr");

                        }
                  }


               myXformInverse = queryTransform(handle, 0);
               myXformInverse.invert();




#ifdef DEBUG
               cout << "Geometry Samples: " << queryGeometrySamples(handle) << endl;
// cout << "scale: " << getFParm ( "scale" ) << endl;
#endif

               // Dump the user parameters to the console
               if(myVerbose == CLUSTER_MSG_DEBUG)
                  VRAY_clusterThis::dumpParameters();

               switch(myMethod) {
                     case CLUSTER_INSTANCE_NOW:
                        inst_gdp = VRAY_Procedural::allocateGeometry();
                        if(myDoMotionBlur == CLUSTER_MB_DEFORMATION)
                           mb_gdp = VRAY_Procedural::allocateGeometry();
                        if(myVerbose > CLUSTER_MSG_QUIET)
                           cout << "VRAY_clusterThis::render() - Using \"instance all the geometry at once\" method" << endl;
                        break;
                     case CLUSTER_INSTANCE_DEFERRED:
                        if(myVerbose > CLUSTER_MSG_QUIET)
                           cout << "VRAY_clusterThis::render() - Using \"addProcedural()\" method" << endl;
                        break;
                  }

               rendered = true;

               // Get the point's attribute offsets
               VRAY_clusterThis::getAttributeOffsets(gdp);

               // Check for required attributes
               VRAY_clusterThis::checkRequiredAttributes();

               // Check for weight attribute if the user wants metaballs
               if((myPrimType == CLUSTER_PRIM_METABALL) && (myPointAttrOffsets.weight.isInvalid())) {

                     cout << "Incoming points must have weight attribute if instancing metaballs! Throwing exception ..." << endl;
                     throw VRAY_clusterThis_Exception("VRAY_clusterThis::render() Incoming points must have weight attribute if instancing metaballs!", 1);
                  }


               if(myPrimType == CLUSTER_FILE) {
                     file_gdp = VRAY_Procedural::allocateGeometry();
                     int file_load_stat = VRAY_clusterThis::preLoadGeoFile(file_gdp);

                     if(!file_load_stat) {
//                           myFileGDP = file_gdp;
                           if(myVerbose > CLUSTER_MSG_INFO)
                              cout << "VRAY_clusterThis::render() Successfully loaded geometry file: " << myGeoFile << endl;
                        }
                     else {
                           throw VRAY_clusterThis_Exception("VRAY_clusterThis::render() Failed to load geometry file ", 1);
                        }
                  }

               // init some vars ...
               myPointAttributes.Cd = (UT_Vector3(1, 1, 1));
               myPointAttributes.v = (UT_Vector3(0, 0, 0));
               myPointAttributes.N = (UT_Vector3(0, 1, 0));
               myPointAttributes.Alpha = 1.0;
               myPointAttributes.pscale = 1.0;
               myPointAttributes.id = 0;

               myNoise.initialize(myNoiseSeed, myNoiseType);

               // Create the attribute "offsets" for the geometry to be instanced
               VRAY_clusterThis::createAttributeOffsets(inst_gdp, mb_gdp);

//changeSetting("surface", "constant Cd ( 1 0 0 )", "object");


               fpreal theta = (2.0 * M_PI) / myNumCopies;
               myInstanceNum = 0;

               if(myCVEX_Exec_pre) {
                     if(myVerbose > CLUSTER_MSG_INFO)
                        cout << "VRAY_clusterThis::render() Executing Pre Process CVEX code" << endl;
                     VRAY_clusterThis::runCVEX(gdp, gdp, myCVEXFname_pre, CLUSTER_CVEX_POINT);
                  }

               /// For each point of the incoming geometry
               GA_FOR_ALL_GPOINTS(gdp, ppt) {
                  myPointAttributes.myPos = ppt->getPos();

                  // get the point's attributes
                  VRAY_clusterThis::getAttributes(ppt, gdp);

#ifdef DEBUG
                  cout << "VRAY_clusterThis::render() " << "theta: " << theta << endl;
#endif

                  uint seed = 37;
                  fpreal dice;
                  bool skip = false;

                  if((myPrimType != CLUSTER_PRIM_CURVE) ||
                        ((myMethod == CLUSTER_INSTANCE_DEFERRED && (myPrimType == CLUSTER_PRIM_CURVE)))) {


                        // For each point, make a number of copies of and recurse a number of times for each copy ...
                        for(int copyNum = 0; copyNum < myNumCopies; copyNum++) {
                              for(int recursionNum = 0; recursionNum < myRecursion; recursionNum++) {

                                    // generate random number to determine to instance or not

                                    dice = SYSfastRandom(seed);
                                    (dice > myBirthProb)?skip = true:skip = false;
//                  cout << dice << " " << skip << endl;
                                    seed = uint(dice * 100);

                                    // Calculate the position for the next instanced object ...
                                    VRAY_clusterThis::calculateNewPosition(theta, copyNum, recursionNum);

                                    if(!skip) {

                                          // Instance an object ...
                                          switch(myMethod) {
                                                   // For the "create all geometry at once" method, instance the object now ...
                                                case CLUSTER_INSTANCE_NOW:
                                                   // Create a primitive based upon user's selection
                                                   // TODO: can later be driven by a point attribute
                                                   switch(myPrimType) {
                                                         case CLUSTER_POINT:
                                                            VRAY_clusterThis::instancePoint(inst_gdp, mb_gdp);
                                                            break;
                                                         case CLUSTER_PRIM_SPHERE:
                                                            VRAY_clusterThis::instanceSphere(inst_gdp, mb_gdp);
                                                            break;
                                                         case CLUSTER_PRIM_CUBE:
                                                            VRAY_clusterThis::instanceCube(inst_gdp, mb_gdp);
                                                            break;
                                                         case CLUSTER_PRIM_GRID:
                                                            VRAY_clusterThis::instanceGrid(inst_gdp, mb_gdp);
                                                            break;
                                                         case CLUSTER_PRIM_TUBE:
                                                            VRAY_clusterThis::instanceTube(inst_gdp, mb_gdp);
                                                            break;
                                                         case CLUSTER_PRIM_CIRCLE:
                                                            VRAY_clusterThis::instanceCircle(inst_gdp, mb_gdp);
                                                            break;
                                                         case CLUSTER_PRIM_METABALL:
                                                            VRAY_clusterThis::instanceMetaball(inst_gdp, mb_gdp);
                                                            break;
                                                         case CLUSTER_FILE:
                                                            VRAY_clusterThis::instanceFile(file_gdp, inst_gdp, mb_gdp);
                                                            break;
                                                            // In case a instance type comes through that's not "legal", throw exception
                                                         default:
                                                            throw VRAY_clusterThis_Exception("VRAY_clusterThis::render() Illegal instance type, exiting ...", 1);
                                                            break;
                                                      }
                                                   break;

                                                   // For the "deferred instance" method, add the procedural now ...
                                                case CLUSTER_INSTANCE_DEFERRED:
                                                   VRAY_Procedural::openProceduralObject();
                                                   VRAY_clusterThisChild * child = new VRAY_clusterThisChild::VRAY_clusterThisChild(this);
                                                   VRAY_Procedural::addProcedural(child);
                                                   VRAY_Procedural::changeSetting("object:geo_velocityblur", "on");
                                                   VRAY_Procedural::closeObject();
//changeSetting("surface", "constant Cd ( 1 0 0 )", "object");
//   changeSetting("object:geo_velocityblur", "on");

                                                   break;
                                             }

                                          myInstanceNum++;

#ifdef DEBUG
                                          cout << "VRAY_clusterThis::render() - myInstanceNum: " << myInstanceNum << std::endl;
#endif
                                       }

                                 } // for number of recursions ...
                           } // for number of copies ...

                     }

                  // User wants a curve instanced on this point
                  if((myPrimType == CLUSTER_PRIM_CURVE) && (myMethod == CLUSTER_INSTANCE_NOW) && (!skip))
                     VRAY_clusterThis::instanceCurve(inst_gdp, mb_gdp, theta, point_num);

                  // Increment our point counter
                  point_num++;

                  // Print out stats to the console
                  if(myVerbose > CLUSTER_MSG_INFO && (myPrimType != CLUSTER_PRIM_CURVE))
                     if((long int)(point_num % stat_interval) == 0)
                        cout << "VRAY_clusterThis::render() Number of points processed: " << point_num << " Number of instances: " << myInstanceNum << endl;

               } // for all points ...


               if(myVerbose > CLUSTER_MSG_QUIET)
                  if(myMethod == CLUSTER_INSTANCE_NOW)
                     if(myDoMotionBlur == CLUSTER_MB_DEFORMATION)
                        cout << "VRAY_clusterThis::render() - Memory usage(MB): " <<
                             (fpreal)(inst_gdp->getMemoryUsage() + mb_gdp->getMemoryUsage() / (1024.0 * 1024.0)) << endl;
                     else
                        cout << "VRAY_clusterThis::render() - Memory usage(MB): " <<
                             (fpreal)(inst_gdp->getMemoryUsage() / (1024.0 * 1024.0)) << endl;

               // If the "instance all the geo at once method" is used, add the the instanced geo for mantra to render ...
               switch(myMethod) {
                     case CLUSTER_INSTANCE_NOW:

                        if(myCVEX_Exec_post) {
                              if(myVerbose > CLUSTER_MSG_INFO)
                                 cout << "VRAY_clusterThis::render() Executing Post Process CVEX code" << endl;
                              VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname_post, CLUSTER_CVEX_POINT);
                           }
                        VRAY_Procedural::openGeometryObject();
                        VRAY_Procedural::addGeometry(inst_gdp, 0.0);

                        if(myDoMotionBlur == CLUSTER_MB_VELOCITY)
                           VRAY_Procedural::addVelocityBlurGeometry(inst_gdp, myShutter, myShutter2);

// float    addVelocityBlurGeometry (GU_Detail *gdp, fpreal pre_blur, fpreal post_blur, const char *velocity_attribute="v")

                        if(myDoMotionBlur == CLUSTER_MB_DEFORMATION)
                           VRAY_Procedural::addGeometry(mb_gdp, myShutter);

                        VRAY_Procedural::setComputeN(1);
//                        setSurface(myMaterial);
                        VRAY_Procedural::closeObject();

                        break;
                     case CLUSTER_INSTANCE_DEFERRED:
                        break;
                  }

               if(myVerbose > CLUSTER_MSG_QUIET && (myPrimType != CLUSTER_PRIM_CURVE))
                  cout << "VRAY_clusterThis::render() Total number of instances: " << myInstanceNum << endl;

               // Save the geo to temp location so it doesn't have to be regenerated for a deep shadow pass, etc.
               if(myMethod == CLUSTER_INSTANCE_NOW && myUseTempFile) {
                     ofstream myGeoStream;
                     // myGeoStream.open("/tmp/thisGeo.bgeo");
                     myGeoStream.open((const char *)myTempFname, ios_base::binary);
                     UT_Options myOptions;
                     inst_gdp->save(myGeoStream, 1, &myOptions);
                     myGeoStream.flush();
                     myGeoStream.close();
                     if(myVerbose > CLUSTER_MSG_QUIET)
                        cout << "VRAY_clusterThis::render() - Saved geometry to temp file: " << myTempFname << endl;
                  }

               if(myPrimType == CLUSTER_FILE)
                  VRAY_Procedural::freeGeometry(file_gdp);

               // We're done, free the original geometry
               VRAY_Procedural::freeGeometry(gdp);

            } /// if (rendered) ...
void
SOP_PrimGroupCentroid::buildTransform(UT_Matrix4 &mat,
                                      const GU_Detail *input_geo,
                                      const UT_Vector3 centroid,
                                      GA_Offset ptOff)
{
    bool                        use_orient = false;
    fpreal                      pscale = 1;

    GA_ROAttributeRef           dir_gah, orient_gah, pscale_gah, rot_gah, scale_gah, trans_gah, up_gah;
    GA_ROHandleF                pscale_h;
    GA_ROHandleV3               dir_h, scale_h, trans_h, up_h;
    GA_ROHandleV4               orient_h, rot_h;

    UT_Matrix4                  pre_xform, xform;
    UT_Quaternion               orient, rot;
    UT_Vector3                  dir, pt_pos, scale, trans, up;

    pt_pos = input_geo->getPos3(ptOff);

    pre_xform.identity();
    pre_xform.translate(centroid[0], centroid[1], centroid[2]);
    pre_xform.invert();

    // Try to find the specific attribute.
    orient_gah = input_geo->findFloatTuple(GA_ATTRIB_POINT,
                                      GA_SCOPE_PUBLIC,
                                      "orient",
                                      4,
                                      4);

    // Found the attribute.
    if (orient_gah.isValid())
    {
        orient_h.bind(orient_gah.getAttribute());
        // Get the attribute value.
        UT_Vector4 value = orient_h.get(ptOff);

        // Construct a quaternion from the values.
        orient.assign(value[0], value[1], value[2], value[3]);
        use_orient = true;
    }


    // Try to find the 'trans' point attribute.
    trans_gah = input_geo->findFloatTuple(GA_ATTRIB_POINT,
                                          GA_SCOPE_PUBLIC,
                                          "trans",
                                          3,
                                          3);

    // We found it.
    if (trans_gah.isValid())
    {
        // Bind the handle to the attribute..
        trans_h.bind(trans_gah.getAttribute());

        // Get the attribute value.
        trans = trans_h.get(ptOff);
    }
    else
        trans.assign(0, 0, 0);

    // Try to find the scale attribute.
    scale_gah = input_geo->findFloatTuple(GA_ATTRIB_POINT,
                                          GA_SCOPE_PUBLIC,
                                          "scale",
                                          3,
                                          3);

    // Try to find the pscale attribute.
    pscale_gah = input_geo->findFloatTuple(GA_ATTRIB_POINT,
                                           GA_SCOPE_PUBLIC,
                                           "pscale",
                                           1,
                                           1);

    //  If the pscale attribute exists, get the value.
    if (pscale_gah.isValid())
    {
        pscale_h.bind(pscale_gah.getAttribute());
        pscale = pscale_h.get(ptOff);
    }

    // The scale attribute exists.
    if (scale_gah.isValid())
    {
        scale_h.bind(scale_gah.getAttribute());
        // Get the scale.
        scale = scale_h.get(ptOff);
    }
    else
    {
        // Use a default scale.
        scale.assign(1, 1, 1);
    }

    // Try to find the specific attribute.
    rot_gah = input_geo->findFloatTuple(GA_ATTRIB_POINT,
                                        GA_SCOPE_PUBLIC,
                                        "rot",
                                        4,
                                        4);

    // Found the attribute.
    if (rot_gah.isValid())
    {
        rot_h.bind(rot_gah.getAttribute());
        // Get the attribute value.
        UT_Vector4 value = rot_h.get(ptOff);

        // Construct a quaternion from the values.
        rot.assign(value[0], value[1], value[2], value[3]);
    }

    if (use_orient)
    {
        xform.instance(pt_pos,
                       dir,
                       pscale,
                       &scale,
                       &up,
                       &rot,
                       &trans,
                       &orient);
    }

    // Need to build the transform manually.
    else
    {
        // Try to find the point Normal attribute.
        dir_gah = input_geo->findNormalAttribute(GA_ATTRIB_POINT);

        // We couldn't find the Normal attribute.
        if (dir_gah.isInvalid())
        {
            // Try to find the velocity attribute.
            dir_gah = input_geo->findVelocityAttribute(GA_ATTRIB_POINT);
        }

        // We found either the normal or velocity attributes.
        if (dir_gah.isValid())
        {
            // Bind the direction handle to the found attribute.
            dir_h.bind(dir_gah.getAttribute());

            dir = dir_h.get(ptOff);
        }
        // Default to the Z-axis.
        else
            dir = UT_Vector3(0,0,1);

        // Try to find the upvector ('up') attribute.
        up_gah = input_geo->findFloatTuple(GA_ATTRIB_POINT,
                                           GA_SCOPE_PUBLIC,
                                           "up",
                                           3,
                                           3);

        // We found the up vector.
        if (up_gah.isValid())
        {
            up_h.bind(up_gah.getAttribute());
            // Get the up vector.
            up = up_h.get(ptOff);
        }
        // Leave the up vector as the zero vector.
        else
            up.assign(0,0,0);

        xform.instance(pt_pos, dir, pscale, &scale, &up, &rot, &trans, 0);
    }

    // Assign the transform.
    mat = pre_xform * xform;
}
void VRAY_clusterThis::preProcess(GU_Detail * gdp)

{

   GEO_Point * ppt;

   long int num_points = (long int) gdp->points().entries();
   long int stat_interval = (long int)(num_points * 0.10) + 1;


   for(uint32 i = gdp->points().entries(); i-- > 0;) {
         ppt = gdp->points()(i);

         myPointList.append(i);

      }



   // If the user wants to build grids for pre processing
   // TODO: Should this be an option?  There may be functions/features that will depend on this ... discuss!
   if(!myPreProcess)
      return;

   if(myVerbose > CLUSTER_MSG_INFO)
      cout << "VRAY_clusterThis::preProcess() Pre Processing Voxels" << std::endl;

//                     openvdb::ScalarGrid::Accessor accessor;
//                     openvdb::FloatTree myTree;
   openvdb::FloatTree::ConstPtr myGeoTreePtr;
   openvdb::VectorTree::ConstPtr myGeoGradTreePtr;

   ParticleList paGeoList(gdp, myPreVDBRadiusMult, myPreVDBVelocityMult);
   openvdb::tools::PointSampler myGeoSampler, geoGradSampler;
//                     openvdb::tools::GridSampling<openvdb::FloatTree>  myGridSampler;

   if(myVerbose == CLUSTER_MSG_DEBUG)
      std::cout << "VRAY_clusterThis::preProcess() paGeoList.size() ... "  << paGeoList.size() << std::endl;

   if(paGeoList.size() != 0) {

         hvdb::Interrupter boss("VRAY_clusterThis::preProcess() Converting particles to level set");

         Settings settings;
         settings.mRadiusMin = myPreRadiusMin;
         settings.mRasterizeTrails = myPreRasterType;
         settings.mDx = myPreDx;  // only used for rasterizeTrails()
         settings.mFogVolume = myPreFogVolume;
         settings.mGradientWidth = myPreGradientWidth;  // only used for fog volume

         float background;

         // background in WS units
         if(myPreWSUnits)
            background = myPreBandWidth;
         // background NOT in WS units
         else
            background = myPreVoxelSize * myPreBandWidth;

         // Construct a new scalar grid with the specified background value.
         openvdb::math::Transform::Ptr transform =
            openvdb::math::Transform::createLinearTransform(myPreVoxelSize);

//         openvdb::ScalarGrid::Ptr myGeoGrid = openvdb::ScalarGrid::create(background);

         myGeoGrid = openvdb::ScalarGrid::create(background);

         myGeoGrid->setTransform(transform);
         myGeoGrid->setGridClass(openvdb::GRID_LEVEL_SET);

         // Perform the particle conversion.
         this->convert(myGeoGrid, paGeoList, settings, boss);

         if(myVerbose == CLUSTER_MSG_DEBUG) {
               std::cout << "VRAY_clusterThis::preProcess() - activeVoxelCount(): "
                         << myGeoGrid->activeVoxelCount() << std::endl;
               std::cout << "VRAY_clusterThis::preProcess() - background: "
                         << myGeoGrid->background() << std::endl;
            }

         // Insert the new grid into the ouput detail.
         UT_String gridNameStr = "ClusterGrid";
         myGeoGrid->insertMeta("float type", openvdb::StringMetadata("averaged_velocity"));
         myGeoGrid->insertMeta("name", openvdb::StringMetadata((const char *)gridNameStr));
         myGeoGrid->insertMeta("VoxelSize", openvdb::FloatMetadata(myPreVoxelSize));
         myGeoGrid->insertMeta("background", openvdb::FloatMetadata(background));


         UT_Vector3 pos, seed_pos, currVel;
//         const GA_PointGroup * sourceGroup = NULL;
         long int pt_counter = 0;
         float radius = 5.0f;

         if(myVerbose > CLUSTER_MSG_INFO)
            std::cout << "VRAY_clusterThis::preProcess() - Massaging data ... " << std::endl;

         long int pointsFound = 0;
         GEO_AttributeHandle inst_vel_gah = gdp->getPointAttribute("v");
         GEO_AttributeHandle source_vel_gah = gdp->getPointAttribute("v");
         GEO_AttributeHandle inst_N_gah = gdp->getPointAttribute("N");
         GEO_AttributeHandle source_N_gah = gdp->getPointAttribute("N");
         GEO_AttributeHandle inst_Cd_gah = gdp->getPointAttribute("Cd");
         GEO_AttributeHandle source_Cd_gah = gdp->getPointAttribute("Cd");
         GEO_AttributeHandle inst_Alpha_gah = gdp->getPointAttribute("Alpha");
         GEO_AttributeHandle source_Alpha_gah = gdp->getPointAttribute("Alpha");

         if(!inst_vel_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance velocity handle invalid, exiting ...", 1);
         if(!source_vel_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source velocity handle invalid, exiting ...", 1);
         if(!inst_N_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance normal handle invalid, exiting ...", 1);
         if(!source_N_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source normal handle invalid, exiting ...", 1);
         if(!inst_Cd_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance color handle invalid, exiting ...", 1);
         if(!source_Cd_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source color handle invalid, exiting ...", 1);
         if(!inst_Alpha_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance alpha handle invalid, exiting ...", 1);
         if(!source_Alpha_gah.isAttributeValid())
            throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source alpha handle invalid, exiting ...", 1);

         openvdb::FloatTree::ValueType sampleResult;
         openvdb::VectorGrid::ValueType gradResult;
         const openvdb::FloatTree aTree;
         openvdb::FloatTree& myGeoTree = myGeoGrid->treeRW();

         openvdb::tools::Filter<openvdb::FloatGrid> preProcessFilter(*myGeoGrid);
//                           openvdb::tools::Filter<openvdb::FloatGrid> barFilter(myGeoGrid);

         if(myPreVDBMedianFilter)
            preProcessFilter.median();

         if(myPreVDBMeanFilter)
            preProcessFilter.mean();

         if(myPreVDBMeanCurvatureFilter)
            preProcessFilter.meanCurvature();

         if(myPreVDBLaplacianFilter)
            preProcessFilter.laplacian();

//                           if(myVDBReNormalizeFilter)
//                              float r = barFilter.renormalize(3, 0.1);

         if(myPreVDBOffsetFilter)
            preProcessFilter.offset(myPreVDBOffsetFilterAmount);


         myGradientGrid = openvdb::VectorGrid::create();
//         openvdb::VectorGrid::Ptr myGradientGrid = openvdb::VectorGrid::create();
         myGradientGrid->setTransform(transform);
//               myGradientGrid->setGridClass(openvdb::GRID_FOG_VOLUME );
         myGradientGrid->setGridClass(openvdb::GRID_LEVEL_SET);

         openvdb::tools::Gradient<openvdb::ScalarGrid> myGradient(*myGeoGrid);
         myGradientGrid = myGradient.process();
         openvdb::VectorTree& myGeoGradTree = myGradientGrid->treeRW();

         gridNameStr = "ClusterGradientGrid";
         myGradientGrid->insertMeta("vector type", openvdb::StringMetadata("covariant (gradient)"));
         myGradientGrid->insertMeta("name", openvdb::StringMetadata((const char *)gridNameStr));
         myGradientGrid->insertMeta("VoxelSize", openvdb::FloatMetadata(myPreVoxelSize));
         myGradientGrid->insertMeta("background", openvdb::FloatMetadata(background));


         GA_FOR_ALL_GPOINTS(gdp, ppt) {
//                              myCurrPtOff = ppt->getMapOffset();
//                              std::cout << "myCurrPtOff: " << myCurrPtOff << std::endl;

            pos = ppt->getPos();

// Vec3d worldToIndex   (  const Vec3d &     xyz    )    const

//                              openvdb::Vec3R theIndex =
//                                 (openvdb::Vec3R(pos[0], pos[1], pos[2]));
            openvdb::Vec3R theIndex =
               myGeoGrid->worldToIndex(openvdb::Vec3R(pos[0], pos[1], pos[2]));

            radius = static_cast<fpreal>(ppt->getValue<fpreal>(myInstAttrRefs.pointVDBRadius, 0));
//                                    std::cout << "radius: " << radius << std::endl;

// static bool    sample (const TreeT &inTree, const Vec3R &inCoord, typename TreeT::ValueType &sampleResult)
            const openvdb::Vec3R  inst_sample_pos(theIndex[0], theIndex[1], theIndex[2]);

            bool success = myGeoSampler.sample(myGeoTree, inst_sample_pos, sampleResult);

            geoGradSampler.sample(myGeoGradTree, inst_sample_pos, gradResult);
//
//                              std::cout << "success: " << success << "\tpos: " << pos
//                                        << "\tinst_sample_pos: " << inst_sample_pos
//                                        << "\tsampleResult: " << sampleResult << std::endl;

//ValueType    sampleWorld (const Vec3R &pt) const
//ValueType    sampleWorld (Real x, Real y, Real z) const

            // if the instanced point is within the vdb volume
            if(success) {
//                                    std::cout << "pos: " << pos << " inst_sample_pos: "
//                                              << inst_sample_pos << " sampleResult: " << sampleResult
//                                              << " gradResult: " << gradResult << std::endl;
//                                    float weight;
                  pointsFound++;

                  inst_vel_gah.setElement(ppt);
                  currVel = inst_vel_gah.getV3();

                  UT_Vector3 gradVect = UT_Vector3(gradResult[0], gradResult[1], gradResult[2]);

                  ppt->setPos(pos + (myPrePosInfluence *(sampleResult * gradVect)));
//                                    ppt->setPos(pos + (sampleResult * myPosInfluence *(currVel / myFPS)));

//                                    inst_vel_gah.setV3(currVel * ((1 / sampleResult) * radius));
                  inst_vel_gah.setV3(currVel + (myPreVelInfluence *(sampleResult * gradVect)));

//                                    std::cout << "currVel: " << currVel << " sampleResult " << sampleResult
//                                              << " new vel: " <<  currVel * sampleResult << std::endl;

                  inst_N_gah.setV3(inst_N_gah.getV3() + (myPreNormalInfluence *(sampleResult * gradVect)));

//                        inst_Cd_gah.setElement(ppt);
//                        inst_Cd_gah.setV3(inst_Cd_gah.getV3() * abs(sampleResult));
//
//
//                        inst_Alpha_gah.setElement(ppt);
//                        inst_Alpha_gah.setF(inst_Alpha_gah.getF() * abs(sampleResult));

               } // if the instanced point is within the vdb volume

            if(myVerbose == CLUSTER_MSG_DEBUG) {
                  pt_counter++;
                  if((long int)(pt_counter % (stat_interval * myNumCopies * myRecursion)) == 0) {
                        cout << "VRAY_clusterThis::preProcess() Number of points pre processed: " << pt_counter
                             << "\t - Number of points found in vdb grid: " << pointsFound << std::endl;
                     }
               }

         }