Esempio n. 1
0
void OctreeBox::Split()
{
        C = new OctreeBox[8];
        for(int i=0;i<8;i++)
        {
                C[i].level=level-1;
        };

        UT_Vector3 c = bbox.center();
        UT_Vector3 m = bbox.minvec();
        UT_Vector3 M = bbox.maxvec();

        C[0].bbox = UT_BoundingBox(m.vec[0],m.vec[1],m.vec[2],c.vec[0],c.vec[1],c.vec[2]);

        C[1].bbox = UT_BoundingBox(c.vec[0],m.vec[1],m.vec[2],M.vec[0],c.vec[1],c.vec[2]);

        C[2].bbox = UT_BoundingBox(m.vec[0],c.vec[1],m.vec[2],c.vec[0],M.vec[1],c.vec[2]);

        C[3].bbox = UT_BoundingBox(m.vec[0],m.vec[1],c.vec[2],c.vec[0],c.vec[1],M.vec[2]);

        C[4].bbox = UT_BoundingBox(m.vec[0],c.vec[1],c.vec[2],c.vec[0],M.vec[1],M.vec[2]);

        C[5].bbox = UT_BoundingBox(c.vec[0],m.vec[1],c.vec[2],M.vec[0],c.vec[1],M.vec[2]);

        C[6].bbox = UT_BoundingBox(c.vec[0],c.vec[1],m.vec[2],M.vec[0],M.vec[1],c.vec[2]);

        C[7].bbox = UT_BoundingBox(c.vec[0],c.vec[1],c.vec[2],M.vec[0],M.vec[1],M.vec[2]);
};
void
SOP_PrimGroupCentroid::boundingBox(const GU_Detail *input_geo,
                                   GA_Range &pr_range,
                                   const GA_PrimitiveList &prim_list,
                                   UT_Vector3 &pos)
{
    GA_Range                    pt_range;

    UT_BoundingBox              bbox;

    // Initialize the bounding box to contain nothing and have
    // no position.
    bbox.initBounds();

    // Iterate over each primitive in the range.
    for (GA_Iterator pr_it(pr_range); !pr_it.atEnd(); ++pr_it)
    {
        // Get the range of points for the primitive using the
        // offset from the primitive list.
        pt_range = prim_list.get(*pr_it)->getPointRange();

        // For each point in the primitive, enlarge the bounding
        // box to contain it.
        for (GA_Iterator pt_it(pt_range); !pt_it.atEnd(); ++pt_it)
            bbox.enlargeBounds(input_geo->getPos3(*pt_it));
    }

    // Extract the center.
    pos = bbox.center();
}
Esempio n. 3
0
/// \todo: build ray cache and intersect properly
int GU_CortexPrimitive::intersectRay( const UT_Vector3 &o, const UT_Vector3 &d, float tmax, float tol, float *distance, UT_Vector3 *pos, UT_Vector3 *nml, int accurate, float *u, float *v, int ignoretrim ) const
{
	UT_BoundingBox bbox;
	getBBox( &bbox );
	
	float dist;
	int result = bbox.intersectRay( o, d, tmax, &dist, nml );
	if ( result )
	{
		if ( distance )
		{
			*distance = dist;
		}
		
		if ( pos )
		{
			*pos = o + dist * d;
		}
	}
	
	return result;
}
Esempio n. 4
0
void OctreeBox::Build(GU_Detail& gdp)
{
        if(!filled) return;

        if(level == 0)
        {
                //if(count < 1) return;
                int div[3] = {1,1,1};
                GEO_Primitive* pl = GU_PrimVolume::buildFromFunction(&gdp,func,bbox,div[0],div[1],div[2]);

                if(GBisAttributeRefValid(at))
                {
                        int* ct = pl->castAttribData<int>(at);
                        *ct = count;
                };

                if(GBisAttributeRefValid(rt))
                {
                        float* ct = pl->castAttribData<float>(rt);
                        *ct = radius;
                };

                if(GBisAttributeRefValid(it))
                {
                        int* ct = pl->castAttribData<int>(it);
                        ct[0] = float(bbox.centerX()-parentbbox.xmin())/parentbbox.sizeX()*maxlevel;
                        ct[1] = float(bbox.centerY()-parentbbox.ymin())/parentbbox.sizeY()*maxlevel;
                        ct[2] = float(bbox.centerZ()-parentbbox.zmin())/parentbbox.sizeZ()*maxlevel;
                };

        }
        else
        {
                for(int i=0;i<8;i++) C[i].Build(gdp);
        }

        return;
};
Esempio n. 5
0
void wendy_GIO_ROP::save_mata_ass(string arDsoPath,string dpCachePath,GU_Detail *gdp )
{
    //get arnold dso path


    g_particle_mataAss assROP;
    ofstream fout;
    string getCacheDP=dpCachePath;

    stringstream ss(getCacheDP);
    string sub_str;
    vector <string> sp_strPath;
    sp_strPath.clear();
    while(getline(ss,sub_str,'.'))
    {
        sp_strPath.push_back(sub_str);
    }

    string newAssPathName = sp_strPath[0]+"."+sp_strPath[1]+string(".ass");
    fout.open(newAssPathName);
    assROP.setGioCachePath(getCacheDP);  // set Link GIO CACHE
    for (GA_AttributeDict::iterator it = gdp->getAttributeDict(GA_ATTRIB_POINT).begin(GA_SCOPE_PUBLIC); !it.atEnd(); ++it)
    {
        GA_Attribute *attrib = it.attrib();
        string attName( attrib->getName() );
        assROP.inserExtraMataInfo(attName);
    }
    //set ass bbox
    UT_BoundingBox BBOX;
    gdp->getBBox(&BBOX);
    BBOX.expandBounds(2,2,2);
    float min_x=BBOX.xmin();
    float min_y=BBOX.xmin();
    float min_z=BBOX.xmin();
    float max_x=BBOX.xmax();
    float max_y=BBOX.ymax();
    float max_z=BBOX.zmax();
    assROP.setBBOX(min_x,min_y,min_z,max_x,max_y,max_z);
    assROP.setDsoPath(arDsoPath);
    assROP.save(fout);
    fout.close();
}
Esempio n. 6
0
bool OctreeBox::Insert(float*P)
{
        UT_Vector3 p(P);
        if(!bbox.isInside(p)) return false;

        filled = true;

        if(level != 0)
        {
                if(C == NULL) Split();
                for(int i=0;i<8;i++)
                {
                        if(C[i].Insert(P)) break;
                };
        }
        else
        {
                if(P[3] > radius) radius = P[3];
                count++;
        };

        return true;
};
Esempio n. 7
0
bool
GusdGU_PackedUSD::getBounds(UT_BoundingBox &box) const
{
    // Box caching is handled in getBoundsCached()
#if SYS_VERSION_FULL_INT < 0x12000000
    if( m_boundsCache.isValid() )
    {
        box = m_boundsCache;
        return true;
    }
#endif

    UsdPrim prim = getUsdPrim();

    if( !prim ) {
        UT_ASSERT_MSG(0, "Invalid USD prim");
    }

    if(UsdGeomImageable visPrim = UsdGeomImageable(prim))
    {
        TfTokenVector purposes = GusdPurposeSetToTokens(m_purposes);

        if ( GusdBoundsCache::GetInstance().ComputeUntransformedBound(
                prim,
                UsdTimeCode( m_frame ),
                purposes,
                box )) {
#if SYS_VERSION_FULL_INT < 0x12000000
            m_boundsCache = box;
#endif
            return true;
        }
    }
    box.makeInvalid();
    return false;
}
OP_ERROR
SOP_PrimCentroid::cookMySop(OP_Context &context)
{
    fpreal                      now;
    int                         method;

    const GA_Attribute          *source_attr;
    const GA_AttributeDict      *dict;
    GA_AttributeDict::iterator  a_it;
    GA_Offset                   ptOff;
    GA_RWAttributeRef           n_gah;
    GA_RWHandleV3               n_h;

    const GEO_Primitive         *prim;

    const GU_Detail             *input_geo;

    UT_BoundingBox              bbox;
    UT_String                   pattern, attr_name;
    UT_WorkArgs                 tokens;

    now = context.getTime();

    if (lockInputs(context) >= UT_ERROR_ABORT)
        return error();

    // Clear out any previous data.
    gdp->clearAndDestroy();

    // Get the input geometry as read only.
    GU_DetailHandleAutoReadLock gdl(inputGeoHandle(0));
    input_geo = gdl.getGdp();

    // Find out which calculation method we are attempting.
    method = METHOD(now);

    // Create the standard point normal (N) attribute.
    n_gah = gdp->addNormalAttribute(GA_ATTRIB_POINT);

    // Bind a read/write attribute handle to the normal attribute.
    n_h.bind(n_gah.getAttribute());

    // Construct an attribute reference map to map attributes.
    GA_AttributeRefMap hmap(*gdp, input_geo);

    // Get the attribute selection string.
    ATTRIBUTES(pattern, now);

    // Make sure we entered something.
    if (pattern.length() > 0)
    {
        // Tokenize the pattern.
        pattern.tokenize(tokens, " ");

        // The primitive attributes on the incoming geometry.
        dict = &input_geo->primitiveAttribs();

        // Iterate over all the primitive attributes.
        for (a_it=dict->begin(GA_SCOPE_PUBLIC); !a_it.atEnd(); ++a_it)
        {
            // The current attribute.
            source_attr = a_it.attrib();

            // Get the attribute name.
            attr_name = source_attr->getName();

            // If the name doesn't match our pattern, skip it.
            if (!attr_name.matchPattern(tokens))
                continue;

            // Create a new point attribute on the current geometry
            // that is the same as the source attribute.  Append it and
            // the source to the map.
            hmap.append(gdp->addPointAttrib(source_attr).getAttribute(),
                        source_attr);
        }

        // Copy local variables.
        if (COPY(now))
        {
            // Traverse the variable names on the input geometry and attempt to
            // copy any that match to our new geometry.
            input_geo->traverseVariableNames(
                SOP_PrimCentroid::copyLocalVariables,
                gdp
            );
        }
    }

    // Get the list of input primitives.
    const GA_PrimitiveList &prim_list = input_geo->getPrimitiveList();

    // Add points for each primitive.
    ptOff = gdp->appendPointBlock(input_geo->getNumPrimitives());

    // Iterate over primitives using pages.
    for (GA_Iterator it(input_geo->getPrimitiveRange()); !it.atEnd(); ++it)
    {
        // Get the primitive from the list.
        prim = (const GEO_Primitive *) prim_list.get(*it);

        if (method)
        {
            // Get the bounding box for the primitive and set the point's
            // position to be the center of the box.
            prim->getBBox(&bbox);
            gdp->setPos3(ptOff, bbox.center());
        }
        else
            // Set the point's position to be the bary center of the primitive
            gdp->setPos3(ptOff, prim->baryCenter());

        // Set the point's normal to be the normal of the primitive.
        n_h.set(ptOff, prim->computeNormal());

        // If we are copying attributes, copy the primitive attributes from
        // the current primitive to the new point.
        if (hmap.entries() > 0)
            hmap.copyValue(GA_ATTRIB_POINT, ptOff, GA_ATTRIB_PRIMITIVE, *it);

        // Increment the point offset.
        ptOff++;
    }

    unlockInputs();
    return error();
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
	
	logger.setLogLevel(Logging::Debug);
	struct args a;
	setArgs(a, argc, argv);

    GU_Detail		 gdp;
	bool binary = false;
	bool bbox = false;		

	if( a.b )
		binary = true;

	// convert all files in directory from hsff to geo or bgeo
	if (a.cd || a.c)
	{
		logger.debug("Found argument -cd or -c, trying to convert files in a directory.");
		std::vector<std::string> filesToConvert;
		if( a.cd )
		{
			logger.debug("Found argument -cd trying to convert files in a directory.");
			std::string info("Directory: ");
			info += a.cdDir;
			logger.debug(info);

			if( binary )
				logger.debug("Exporting binary bgeo files");
			else
				logger.debug("Exporting ascii geo files");

			//dirname.harden(argv[1]); // what does this mean, harden???

			fs::path p(a.cdDir);
			getHsffFiles(p, filesToConvert, binary);
		}else{
			logger.debug("Found argument -c trying to convert exactly one file.");
			//filename = UT_String(args.argp('c'));
			std::string info("Filename.");
			info += a.cFile;
			logger.debug(info);
			filesToConvert.push_back(a.cFile);
		}

		// export geo loop
		for( uint fId = 0; fId < filesToConvert.size(); fId++)
		{
			Hsff inFile(filesToConvert[fId]);
			if(!inFile.good)
			{
				logger.error(std::string("Error: problems reading file ") + filesToConvert[fId]);
				//cerr << "Error: problems reading file " << filesToConvert[fId] << "\n";
				inFile.close();
				continue;		
			}
			logger.debug(std::string("Converting file ") + filesToConvert[fId]);
			//cout << "Converting " << filesToConvert[fId] << "\n";
			inFile.doBinary = binary;

			unsigned int geoType = inFile.readGeoType();
			switch(geoType)
			{
			case PARTICLE:
				//cout << "Detected particle file.\n";
				createParticleGeo(inFile);
				break;
			case FLUID:
				//cout << "Detected fluid file.\n";
				createFluidGeo(inFile);
				break;
			case MESH:
				//cout << "Detected mesh file.\n";
				createMeshGeo(inFile);
				break;
			case CURVE:
				//cout << "Detected curve file.\n";
				createCurveGeo(inFile);
				break;
			case NURBS:
				//cout << "Detected nurbs file.\n";
				createNurbsGeo(inFile);
				break;
			}

			inFile.close();
		}
		return 0;
	}


	// get bbox from 1st argument
	if (a.bbox)
	{	
		std::string info("Getting BBox of ");
		info += a.bboxfile;
		logger.debug(info);
		if( !isValid(fs::path(a.bboxfile)))
		{
			logger.error("Could not read file.");
			return 1;
		}
		UT_BoundingBox bbox;
		getBBox(a.bboxfile, bbox);
		cout << "BBox: " << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin() << " " << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax() << "\n";
	}

	if (a.ptc)
	{
		std::string info("Getting pointcloud of ");
		info += a.ptcfile;
		logger.debug(info);
		std::string outFile = pystring::replace(a.ptcfile, ".geo", ".hsffp"); // add a 'p' to show that it is a point cloud file from this tool
		if( pystring::endswith(a.ptcfile, "bgeo"))
			outFile = pystring::replace(a.ptcfile, ".bgeo", ".hsffp"); // add a 'p' to show that it is a point cloud file from this tool
		UT_BoundingBox bbox;
		readPtc(a.ptcfile, outFile, a.ptcdv, bbox);
		cout << "BBox: " << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin() << " " << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax() << "\n";
	}

	//cout << "numargs: " << args.argc() << "\n"; 

	
	
 //   if (args.argc() == 3)
	//{
	//	UT_String dobin;
	//	
	//	dobin.harden(argv[2]);
	//	if(dobin.isInteger())
	//	{
	//		if( dobin.toInt() == 0)
	//			binary = true;
	//		else
	//			binary = false;
	//	}
	//}

	//if(binary)
	//	cout << "Writing from source dir " << dirname << " as binary\n";
	//else
	//	cout << "Writing from source dir " << dirname << " as ascii\n";
	


    return 0;

}
Esempio n. 10
0
int 
main(int argc, char *argv[])
{
    
    // Init:   
    CMD_Args args;
    args.initialize(argc, argv);
    args.stripOptions("r:v");
    if (args.argc() < 3)
    {
        usage(argv[0]);
        return 1;
    }

    // Options:
    int res     = 256;
    int verbose = 0;
    if(args.found('r')) res     = atoi(args.argp('r'));       
    if(args.found('v')) verbose = 1;
    UT_String dcm_file, gdp_file;
    gdp_file.harden(argv[argc-2]);
    dcm_file.harden(argv[argc-1]);
    
    #if 1
    // Open GDP with samples:
    GU_Detail gdp;
    UT_BoundingBox bbox;
    if (!gdp.load(gdp_file, 0).success())
    {
        cerr << "Cant open " << gdp_file << endl;
        return 1;
    }
   
    // Points arrays and bbox details: 
    gdp.getBBox(&bbox);
    int range = gdp.getNumPoints();  
    UT_Vector3Array         positions(range);
    UT_ValArray<int>        indices(range);
    
    const GEO_Point *ppt;
    const GEO_PointList plist = gdp.points();
    for (int i = 0; i < gdp.getNumPoints(); i++)
    {
        ppt = plist(i);
        UT_Vector3 pos = ppt->getPos3();
        positions.append(pos);
        indices.append(i);
    }

    if (verbose)
        cout << "Points in gdp      : " <<  positions.entries() << endl;

    // Point Grid structures/objects:
    UT_Vector3Point accessor(positions, indices);
    UT_PointGrid<UT_Vector3Point> pointgrid(accessor);

    // Can we build it?
    if (!pointgrid.canBuild(res, res, res))
    {
        cout << "Can't build the grid!" << endl; 
        return 1;
    }
    // Build it:
    pointgrid.build(bbox.minvec(), bbox.size(), res, res, res);

    if (verbose)
    {
        cout << "Point grid res     : " << res << "x" << res << "x" << res << endl;
        cout << "Bounding box size  : " << bbox.size().x() << ", " << bbox.size().y() << ", " << bbox.size().z() << endl;
        cout << "Bounding box center: " << bbox.center().x() << ", " << bbox.center().y() << ", " << bbox.center().z() << endl;
        cout << "Pointgrid mem size : " << pointgrid.getMemoryUsage() << endl;
        cout << "Voxel size is      : " << pointgrid.getVoxelSize() << endl;
        cout << "Total grid points  : " << pointgrid.entries() << endl;
    }
    #endif

    // Open rat (our random access, variable array length storage):
    IMG_DeepShadow dsm;
    dsm.setOption("compression", "0");
    dsm.setOption("zbias", "0.05");
    dsm.setOption("depth_mode", "nearest");
    dsm.setOption("depth_interp", "discrete");
    dsm.open(dcm_file, res*res, res);
    dsm.getTBFOptions()->setOptionV3("bbox:min" , bbox.minvec());
    dsm.getTBFOptions()->setOptionV3("bbox:max" , bbox.maxvec()); 
    
    if (verbose)
        cout << "DCM created res    : " << res*res << "x" << res << endl;
      
    #if 1
    // db_* debug variables...
    int db_index = 0;
    int db_uindex = 0;
    int db_av_iter = 0;

    // Put point into deep pixels:
    Locker locker;
    Timer timer;
    timer.start();
    parallel_fillDCM(res, &dsm, &pointgrid, &positions, &locker);
    cout <<     "Creation time      : " << timer.current() << endl;
    if (verbose)
    {
        cout << "Total voxels       : " << db_index  << endl;
        cout << "Written voxel      : " << db_uindex << endl;
        cout << "Points per voxel   : " << (float)db_av_iter / db_uindex << endl;
    }
    timer.start();
    dsm.close();
    cout <<     "Saving time        : " << timer.current() << endl;
    if (verbose)
        cout << "Deep map closed." << endl;
    return 0;
    #endif
}
Esempio n. 11
0
OP_ERROR SOP_Scallop::cookMySop(OP_Context &context)
{
        //OP_Node::flags().timeDep = 1;

        bool clip = (lockInputs(context) < UT_ERROR_ABORT);

        UT_BoundingBox bbox;

        if(clip)
        {
                const GU_Detail* input = inputGeo(0,context);
                if(input != NULL)
                {
                        //UT_Matrix4 bm;
                        int res = input->getBBox(&bbox);
                        if(res == 0) clip = false;
                }
                else clip = false;
                unlockInputs();
        };

        float now = context.getTime();

        Daemon::now=now;
        Daemon::caller=this;

        Daemon::bias = evalFloat("bias",0,now);

        UT_Ramp ramp;
        float   rampout[4];

        bool useRamp = (evalInt("parmcolor",0,now)!=0);

        if(useRamp)
        {
                //PRM_Template *rampTemplate = PRMgetRampTemplate ("ramp", PRM_MULTITYPE_RAMP_RGB, NULL, NULL);
                if (ramp.getNodeCount () < 2)
                {
                        ramp.addNode (0, UT_FRGBA (0, 0, 0, 1));
                        ramp.addNode (1, UT_FRGBA (1, 1, 1, 1));
                };
                updateRampFromMultiParm(now, getParm("ramp"), ramp);
        };

        gdp->clearAndDestroy();

        bool showPts = (evalInt("showpts",0,now)!=0);

		/*
        if(showPts)
        {
                float sz = evalInt("ptssz",0,now);
                if(sz > 0)
                {
                        float one = 1.0f;

                        gdp->addAttribute("showpoints",4,GA_ATTRIB_FLOAT_&one);
                        gdp->addAttribute("revealsize",4,GB_ATTRIB_FLOAT,&sz);
                };
        };
		*/

        int cnt = evalInt("daemons", 0, now);

        Daemon* daemons=new Daemon[cnt];

        float weights = 0;

        int totd=0;

        for(int i=1;i<=cnt;i++)
        {
                bool skip = (evalIntInst("enabled#",&i,0,now)==0);
                if(skip) continue;

                Daemon& d = daemons[totd];

                UT_String path = "";
                evalStringInst("obj#", &i, path, 0, now);

                if(path == "") continue;

                SOP_Node* node = getSOPNode(path);

                OBJ_Node* obj = dynamic_cast<OBJ_Node*>(node->getParent());

                if(obj == NULL) continue;

                addExtraInput(obj, OP_INTEREST_DATA);

                //d.xform  = obj->getWorldTransform(context); // 10.0
                obj->getWorldTransform(d.xform, context);

                d.weight = evalFloatInst("weight#",&i,0,now);

                if(!useRamp)
                {
                        d.c[0] = evalFloatInst("color#",&i,0,now);
                        d.c[1] = evalFloatInst("color#",&i,1,now);
                        d.c[2] = evalFloatInst("color#",&i,2,now);
                };

                int mth = evalIntInst("model#",&i,0,now);

                switch(mth)
                {
                case 1:
                        d.method = Methods::Spherical;
                        break;
                case 2:
                        d.method = Methods::Polar;
                        break;
                case 3:
                        d.method = Methods::Swirl;
                        break;
                case 4:
                        d.method = Methods::Trigonometric;
                        break;
                case 5:
                        {
                                UT_String script;
                                evalStringInst("vexcode#", &i, script, 0, now);
                                d.SetupCVEX(script);
                                if(d.useVex)
                                {
                                        OP_Node* shop = (OP_Node*)findSHOPNode(script);
                                        addExtraInput(shop, OP_INTEREST_DATA);
                                }
                                break;
                        }
                case 0:
                default:
                        d.method = Methods::Linear;
                };

                d.power = evalFloatInst("power#",&i,0,now);
                d.radius = evalFloatInst("radius#",&i,0,now);
                d.parameter = evalFloatInst("parameter#",&i,0,now);

                weights+=d.weight;
                totd++;
        };

        if(totd == 0)
        {
                delete [] daemons;
                return error();
        }

        float base = 0.0;
        for(int i=0;i<totd;i++)
        {
                Daemon& d = daemons[i];
                d.range[0]=base;
                d.range[1] = base+d.weight/weights;
                base=d.range[1];
        };

        int total = evalInt("count",0,now);
        int degr = evalInt("degr",0,now);

        total >>= degr;

		GA_RWHandleI cntt(gdp->addIntTuple(GA_ATTRIB_POINT, "count", 4, GA_Defaults(1.0)));


        GB_AttributeRef dt(gdp->addDiffuseAttribute(GEO_POINT_DICT));
        gdp->addVariableName("Cd","Cd");

        UT_Vector3 current(0,0,0);
        float C[3] = { 0,0,0 };

        float R=1.0f;
        bool trackRadii = (evalInt("trackradii",0,now)!=0);
        float rScale = evalFloat("radiiscale",0,now);
        GB_AttributeRef rt;
        if(trackRadii)
        {
                float one=1.0f;
                rt = gdp->addPointAttrib("width",4,GB_ATTRIB_FLOAT,&one);
                if(!GBisAttributeRefValid(rt)) trackRadii=false;
                else gdp->addVariableName("width","WIDTH");
        };

        float zero=0.0f;
        GB_AttributeRef pt = gdp->addPointAttrib("parameter",4,GB_ATTRIB_FLOAT,&zero);
        if(GBisAttributeRefValid(pt)) gdp->addVariableName("parameter","PARAMETER");
        float param=0.0f;

        srand(0);

        UT_Interrupt* boss = UTgetInterrupt();
        boss->opStart("Computing...");

        for(int i=-50;i<total;i++)
        {
                bool ok = false;

                if (boss->opInterrupt()) break;

                float w = double(rand())/double(RAND_MAX);

                for(int j=0;j<totd;j++)
                {
                        ok = daemons[j].Transform(w,current,C,R,param);
                        if(ok) break;
                };

                if(i<0) continue;

                if(clip)
                {
                        if(!bbox.isInside(current)) continue;
                };

                if(ok)
                {
                        GEO_Point* p = gdp->appendPoint();
                        p->setPos(current);

                        float* Cd=p->castAttribData<float>(dt);
                        if(useRamp)
                        {
                                ramp.rampLookup(param,C);
                        }
                        memcpy(Cd,C,12);

                        if(trackRadii)
                        {
                                float* _R = p->castAttribData<float>(rt);
                                *_R=rScale*R;
                        };

                        if(GBisAttributeRefValid(pt))
                        {
                                float* _p = p->castAttribData<float>(pt);
                                *_p=param;
                        }
                };
        };

        boss->opEnd();

        delete [] daemons;

        return error();
};
Esempio n. 12
0
void SOP_Scallop::SaveData(float time)
{
        OP_Context context(time);

        bool clip = (lockInputs(context) < UT_ERROR_ABORT);

        UT_BoundingBox bbox;

        if(clip)
        {
                const GU_Detail* input = inputGeo(0,context);
                if(input != NULL)
                {
                        int res = input->getBBox(&bbox);
                        if(res == 0) clip = false;
                }
                else clip = false;
                unlockInputs();
        };

        UT_String file;
        STR_PARM(file,"path", 8, 0, time);

        FILE* fp = fopen(file.buffer(),"wb");

        if(fp == NULL) return;

        float& now=time;
        //////////////////////////////////////////////////////////////////////////

        UT_Ramp ramp;
        float   rampout[4];

        bool useRamp = (evalInt("parmcolor",0,now)!=0);

        if(useRamp)
        {
                //PRM_Template *rampTemplate = PRMgetRampTemplate ("ramp", PRM_MULTITYPE_RAMP_RGB, NULL, NULL);
                if (ramp.getNodeCount () < 2)
                {
                        ramp.addNode (0, UT_FRGBA (0, 0, 0, 1));
                        ramp.addNode (1, UT_FRGBA (1, 1, 1, 1));
                };
                updateRampFromMultiParm(now, getParm("ramp"), ramp);
        };

        Daemon::now=now;

        Daemon::bias = evalFloat("bias",0,now);

        int cnt = evalInt("daemons", 0, now);

        Daemon* daemons=new Daemon[cnt];

        float weights = 0;

        int totd=0;

        for(int i=1;i<=cnt;i++)
        {
                bool skip = (evalIntInst("enabled#",&i,0,now)==0);
                if(skip) continue;

                Daemon& d = daemons[totd];

                UT_String path = "";
                evalStringInst("obj#", &i, path, 0, now);

                if(path == "") continue;

                SOP_Node* node = getSOPNode(path);

                OBJ_Node* obj = dynamic_cast<OBJ_Node*>(node->getParent());

                if(obj == NULL) continue;

                obj->getWorldTransform(d.xform,context);

                d.weight = evalFloatInst("weight#",&i,0,now);

                d.c[0] = evalFloatInst("color#",&i,0,now);
                d.c[1] = evalFloatInst("color#",&i,1,now);
                d.c[2] = evalFloatInst("color#",&i,2,now);

                int mth = evalIntInst("model#",&i,0,now);

                switch(mth)
                {
                case 1:
                        d.method = Methods::Spherical;
                        break;
                case 2:
                        d.method = Methods::Polar;
                        break;
                case 3:
                        d.method = Methods::Swirl;
                        break;
                case 4:
                        d.method = Methods::Trigonometric;
                        break;
                case 5:
                        {
                                UT_String script;
                                evalStringInst("vexcode#", &i, script, 0, now);
                                d.SetupCVEX(script);

                                break;
                        }
                case 0:
                default:
                        d.method = Methods::Linear;
                };

                d.power = evalFloatInst("power#",&i,0,now);
                d.radius = evalFloatInst("radius#",&i,0,now);
                d.parameter = evalFloatInst("parameter#",&i,0,now);

                weights+=d.weight;
                totd++;
        };

        if(totd == 0)
        {
                delete [] daemons;
                return;
        }

        float base = 0.0;
        for(int i=0;i<totd;i++)
        {
                Daemon& d = daemons[i];
                d.range[0]=base;
                d.range[1] = base+d.weight/weights;
                base=d.range[1];
        };

        int total = evalInt("count",0,now);

        //fwrite(&total,sizeof(int),1,fp);

        UT_Vector3 current(0,0,0);
        float* C = data;

        float R=1.0f;
        float rScale = evalFloat("radiiscale",0,now);

        float param=0.0f;

        srand(0);

        for(int i=-50;i<total;i++)
        {
                bool ok = false;

                float w = double(rand())/double(RAND_MAX);

                for(int j=0;j<totd;j++)
                {
                        ok = daemons[j].Transform(w,current,C,R,*G);
                        if(ok) break;
                };

                if(i<0) continue;

                if(clip)
                {
                        if(!bbox.isInside(current)) continue;
                };

                if(ok)
                {
                        if(useRamp)
                        {
                                float out[4];
                                ramp.rampLookup(data[3],out);
                                memcpy(data,out,12);
                        }
                        fwrite(current.vec,12,1,fp); // P
                        float r = R*rScale;
                        fwrite(&r,4,1,fp); // R
                        fwrite(data,16,1,fp); // Cs+p
                };
        };

        delete [] daemons;

        //////////////////////////////////////////////////////////////////////////

        fclose(fp);
};
Esempio n. 13
0
void SOP_Scallop::SaveDivMap(float time)
{
        OP_Context context(time);

        bool clip = (lockInputs(context) < UT_ERROR_ABORT);

        UT_BoundingBox bbox;

        if(clip)
        {
                const GU_Detail* input = inputGeo(0,context);
                if(input != NULL)
                {
                        //UT_Matrix4 bm;
                        int res = input->getBBox(&bbox);
                        if(res == 0) clip = false;
                }
                else clip = false;
                unlockInputs();
        };

        if(!clip) return;

        UT_String file;
        STR_PARM(file,"mappath", 11, 0, time);

        float& now=time;
        //////////////////////////////////////////////////////////////////////////

        Daemon::now=now;
        Daemon::bias = evalFloat("bias",0,now);

        int cnt = evalInt("daemons", 0, now);

        Daemon* daemons=new Daemon[cnt];

        float weights = 0;

        int totd=0;

        float maxR = 0;
        for(int i=1;i<=cnt;i++)
        {
                bool skip = (evalIntInst("enabled#",&i,0,now)==0);
                if(skip) continue;

                Daemon& d = daemons[totd];

                UT_String path = "";
                evalStringInst("obj#", &i, path, 0, now);

                if(path == "") continue;

                SOP_Node* node = getSOPNode(path);

                OBJ_Node* obj = dynamic_cast<OBJ_Node*>(node->getParent());

                if(obj == NULL) continue;

                obj->getWorldTransform(d.xform,context);

                d.weight = evalFloatInst("weight#",&i,0,now);

                d.c[0] = evalFloatInst("color#",&i,0,now);
                d.c[1] = evalFloatInst("color#",&i,1,now);
                d.c[2] = evalFloatInst("color#",&i,2,now);

                int mth = evalIntInst("model#",&i,0,now);

                switch(mth)
                {
                case 1:
                        d.method = Methods::Spherical;
                        break;
                case 2:
                        d.method = Methods::Polar;
                        break;
                case 3:
                        d.method = Methods::Swirl;
                        break;
                case 4:
                        d.method = Methods::Trigonometric;
                        break;
                case 5:
                        {
                                UT_String script;
                                evalStringInst("vexcode#", &i, script, 0, now);
                                d.SetupCVEX(script);

                                break;
                        };
                case 0:
                default:
                        d.method = Methods::Linear;
                };

                d.power = evalFloatInst("power#",&i,0,now);
                d.radius = evalFloatInst("radius#",&i,0,now);
                d.parameter = evalFloatInst("parameter#",&i,0,now);

                if(d.radius > maxR) maxR = d.radius;

                weights+=d.weight;
                totd++;
        };

        if(totd == 0)
        {
                delete [] daemons;
                return;
        };

        float base = 0.0;
        for(int i=0;i<totd;i++)
        {
                Daemon& d = daemons[i];
                d.range[0]=base;
                d.range[1] = base+d.weight/weights;
                base=d.range[1];
        };

        //////////////////////////////////////////////////////////////////////////
        int total = evalInt("count",0,now);
        int degr = evalInt("degr",0,now);

        total >>= degr;

        GU_Detail det;

        UT_Vector3 current(0,0,0);
        float C[3] = { 0,0,0 };

        float R=1.0f;

        float param=0.0f;

        srand(0);

        bool medial = (evalInt("mapmedial",0,now)!=0);
        int mapdiv = evalInt("mapdiv",0,now);

        //BoundBox Box;
        OctreeBox O(mapdiv);

        //if(medial)
        //{
                O.bbox=bbox;
        //}
        //else
        //{
        //      BoundBox::limit = evalInt("nodecount", 0, now);

        //      BoundBox::medial = (evalInt("mapmedial",0,now)!=0);

        //      float boxb[6];
        //      memcpy(boxb,bbox.minvec().vec,12);
        //      memcpy(boxb+3,bbox.maxvec().vec,12);
        //      Box.Organize(boxb);
        //};

        for(int i=-50;i<total;i++)
        {
                bool ok = false;

                float w = double(rand())/double(RAND_MAX);

                for(int j=0;j<totd;j++)
                {
                        ok = daemons[j].Transform(w,current,C,R,param);
                        if(ok) break;
                };

                if(i<0) continue;

                //if(medial)
                //{
                        float P[4] = { current.x(), current.y(), current.z(), R };
                        O.Insert(P);
                //}
                //else
                //{
                //      Box.CheckPoint(current.vec);
                //}
        };

        delete [] daemons;

        //////////////////////////////////////////////////////////////////////////

        int ita[3] = {-1,-1,-1};

        //if(medial)
        //{
                int count = 0;
                OctreeBox::at = det.addPrimAttrib("count",4,GB_ATTRIB_INT,&count);
                det.addVariableName("count","COUNT");

                float radius = 0.0f;
                OctreeBox::rt = det.addAttrib("radius",4,GB_ATTRIB_FLOAT,&radius);
                det.addVariableName("radius","RADIUS");

                OctreeBox::it = det.addPrimAttrib("mask",12,GB_ATTRIB_INT,ita);
                det.addVariableName("mask","MASK");

                float box[6] = {bbox.xmin(),bbox.xmax(),bbox.ymin(),bbox.ymax(),bbox.zmin(),bbox.zmax()};
                det.addAttrib("bbox",24,GB_ATTRIB_FLOAT,box);

                O.maxlevel = 0x01<<mapdiv;
                O.parentbbox = bbox;

                O.Build(det);
        //}
        //else  Box.Build(det);

        det.save(file.buffer(),1,NULL);

        // ...SAVE ATLAS

        {
                UT_String atlas =file;
                atlas+=".atlas";
                FILE* fa = fopen(atlas.buffer(),"wb");

                GEO_PrimList& pl = det.primitives();

                int cnt = pl.entries();

                fwrite(&cnt,sizeof(int),1,fa);

                float bb[6] = { bbox.xmin(), bbox.xmax(), bbox.ymin(), bbox.ymax(), bbox.zmin(), bbox.zmax() };
                fwrite(bb,sizeof(float),6,fa);

                fwrite(&(O.maxlevel),sizeof(int),1,fa);
                fwrite(&(O.maxlevel),sizeof(int),1,fa);
                fwrite(&(O.maxlevel),sizeof(int),1,fa);

                for(int i=0;i<cnt;i++)
                {
                        const GEO_PrimVolume* v = dynamic_cast<const GEO_PrimVolume*>(pl[i]);
                        UT_BoundingBox b;
                        v->getBBox(&b);
                        float _bb[6] = { b.xmin(), b.xmax(), b.ymin(), b.ymax(), b.zmin(), b.zmax() };
                        fwrite(_bb,sizeof(float),6,fa);

                        // MASK
                        fwrite(v->castAttribData<int>(OctreeBox::it),sizeof(int),3,fa);
                }

                fclose(fa);
        }
};