Пример #1
0
bool GeoAttributeCopier::createHandles(const attrib_copy& copy, GEO_AttributeHandle& hSrc,
	GEO_AttributeHandle& hDest)
{
	// find source attrib
	hSrc = copy.m_srcGeo->getAttribute(copy.m_srcDict, copy.m_srcName.c_str());
	if(!hSrc.isAttributeValid())
		return false;

	const char* destName_ = copy.m_destName.c_str();
	const GB_Attribute* srcAttrib = hSrc.getAttribute();
	assert(srcAttrib);

	// create attrib if it doesn't exist, or does but data type doesn't match
	bool createAttrib = true;
	GEO_AttributeHandle hExist = m_destGeo.getAttribute(copy.m_destDict, destName_);
	if(hExist.isAttributeValid())
	{
		const GB_Attribute* destAttrib = hExist.getAttribute();
		assert(destAttrib);
		createAttrib = (destAttrib->getType() != srcAttrib->getType());
	}

	if(createAttrib)
	{
		GB_AttributeRef aref = m_destGeo.addAttribute(destName_, srcAttrib->getSize(),
			srcAttrib->getType(), srcAttrib->getDefault(), copy.m_destDict);

		if(!aref.isValid())
			return false;
	}

	hDest = m_destGeo.getAttribute(copy.m_destDict, destName_);
	hDest.setSourceMap(hSrc);
	return true;
}
Пример #2
0
void add_simple_mesh(GU_Detail& gdp,
	const dgal::simple_mesh<Imath::V3f>& smesh,
	const std::string& pointIDAttrib, const std::vector<int>* pointIDs,
	const std::string& polyIDAttrib, const std::vector<int>* polyIDs,
	const std::string& cellTypeAttrib, unsigned int cellType,
	const std::string& cellIDAttrib, unsigned int cellID)
{
	unsigned int first_point = gdp.points().entries();
	unsigned int first_prim = gdp.primitives().entries();

	// create dest points
	for(std::vector<Imath::V3f>::const_iterator it=smesh.m_points.begin();
		it!=smesh.m_points.end(); ++it)
	{
		GEO_Point* pt = gdp.appendPoint();
		pt->setPos(it->x, it->y, it->z);
	}

	GEO_PointList& points = gdp.points();
	GEO_PrimList& prims = gdp.primitives();

	// create dest polys
	for(unsigned int i=0; i<smesh.m_polys.size(); ++i)
	{
		const std::vector<unsigned int>& cpoly = smesh.m_polys[i];

		GEO_PrimPoly* poly = GU_PrimPoly::build(&gdp, cpoly.size(), GU_POLY_CLOSED, 0);
		for(unsigned int j=0; j<cpoly.size(); ++j)
			poly->getVertex(j).setPt(points[cpoly[j] + first_point]);
	}

	// create cell-type attribute
	if(!cellTypeAttrib.empty())
	{
		int defaultv = -1;
		GB_AttributeRef aref = gdp.addAttribute(cellTypeAttrib.c_str(), sizeof(int),
			GB_ATTRIB_INT, &defaultv, GEO_PRIMITIVE_DICT);

		if(aref.isValid())
		{
			unsigned int npolys = prims.entries();
			for(unsigned int i=first_prim; i<npolys; ++i)
				prims[i]->setValue<int32>(aref, static_cast<int>(cellType));
		}
	}

	// create cell-id attribute
	if(!cellIDAttrib.empty())
	{
		int defaultv = -1;
		GB_AttributeRef aref = gdp.addAttribute(cellIDAttrib.c_str(), sizeof(int),
			GB_ATTRIB_INT, &defaultv, GEO_PRIMITIVE_DICT);

		if(aref.isValid())
		{
			unsigned int npolys = prims.entries();
			for(unsigned int i=first_prim; i<npolys; ++i)
				prims[i]->setValue<int32>(aref, static_cast<int>(cellID));
		}
	}

	// create point-id attribute
	if(!pointIDAttrib.empty())
	{
		int defaultv = -1;
		GB_AttributeRef aref = gdp.addAttribute(pointIDAttrib.c_str(), sizeof(int),
			GB_ATTRIB_INT, &defaultv, GEO_POINT_DICT);

		if(aref.isValid() && pointIDs)
		{
			unsigned int sz = std::min(points.entries()-first_point,
				static_cast<unsigned int>(pointIDs->size()));

			for(unsigned int i=0; i<sz; ++i)
				points[i + first_point]->setValue<int32>(aref, (*pointIDs)[i]);
		}
	}

	// create poly-id attribute
	if(!polyIDAttrib.empty())
	{
		int defaultv = 0;
		GB_AttributeRef aref = gdp.addAttribute(polyIDAttrib.c_str(), sizeof(int),
			GB_ATTRIB_INT, &defaultv, GEO_PRIMITIVE_DICT);

		if(aref.isValid() && polyIDs)
		{
			unsigned int sz = std::min(prims.entries()-first_prim,
				static_cast<unsigned int>(polyIDs->size()));

			for(unsigned int i=0; i<sz; ++i)
				prims[i + first_prim]->setValue<int32>(aref, (*polyIDs)[i]);
		}
	}
}