Exemple #1
0
void BccWorld::reduceGroup(unsigned igroup)
{
	const float oldCurveLength = groupCurveLength(m_cluster->group(igroup));
	const unsigned oldNCurves = m_cluster->group(igroup)->numGeometries();
    GeometryArray * reduced = 0;
	
	int i=0;
	for(;i<20;i++) {
		GeometryArray * ir = m_reducer->compute(m_cluster->group(igroup), FitBccMeshBuilder::EstimatedGroupSize);
		if(ir) {
			reduced = ir;
			m_cluster->setGroupGeometry(igroup, reduced);
		}
		else break;
	}
	
	if(!reduced) {
        std::cout<<" insufficient condition for curve reduction, skipped.\n";
        return;
    }
	
	m_totalCurveLength -= oldCurveLength;
	m_totalCurveLength += groupCurveLength(reduced);
	
	m_numCurves -= oldNCurves;
	m_numCurves += reduced->numGeometries();
	
	rebuildGroupTetrahedronMesh(igroup, reduced);
}
Exemple #2
0
bool BccInterface::loadPatchGeometry(BccWorld * world, const std::string & filename)
{
	const std::string oldFilename = FileName;
	FileName = filename;
	GeometryArray * trigeo = new GeometryArray;
	bool res = ReadTriangleData(trigeo);
	if(res) {
		const unsigned n = trigeo->numGeometries();
		std::cout<<"\n bcc interface loading "<<n<<" triangle mesh geometries as patch ";
		m_patchMesh = (ATriangleMesh *)trigeo->geometry(0);
		unsigned i=0;
		for(;i<n;i++) {
            std::vector<AOrientedBox> patchBoxes;
			if(separate((ATriangleMesh *)trigeo->geometry(i),
                patchBoxes)) {
				world->addPatchBoxes(patchBoxes);
                patchBoxes.clear();
            }
		}
	}
	else {
		std::cout<<"\n hes file contains no triangle mesh geometry. ";
	}
	FileName = oldFilename;
	return res;
}
Exemple #3
0
bool KdCluster::leafIntersectRay(KdTreeNode *node, const Ray * eyeRay)
{
	const unsigned num = node->getNumPrims();
	if(num < 1) return false;
	
	GeometryArray * g = group(m_nodeGroupInd[node]);
	if(!g->intersectRay(eyeRay)) return false;
	m_currentGroup = m_nodeGroupInd[node];
	return true;
}
Exemple #4
0
bool BccInterface::loadTriangleGeometry(BccWorld * world, const std::string & filename)
{
	const std::string oldFilename = FileName;
	FileName = filename;
	GeometryArray * trigeo = new GeometryArray;
	bool res = ReadTriangleData(trigeo);
	if(res) {
		const unsigned n = trigeo->numGeometries();
		std::cout<<"\n bcc interface loading "<<n<<" triangle mesh geometries. ";
		world->setTiangleGeometry(trigeo);
	}
	else {
		std::cout<<"\n hes file contains no triangle mesh geometry. ";
	}
	FileName = oldFilename;
	return res;
}
Exemple #5
0
void KinTree::_loadVisualArray(const GeometryArray &visuals, osg::Group *group)
{
    group->removeChildren(0, group->getNumChildren());

    for(size_t i=0; i<visuals.size(); ++i)
    {
        group->addChild(new AkinVisual(visuals[i]));
    }
}
Exemple #6
0
bool BccInterface::loadCurveGeometry(BccWorld * world, const std::string & filename)
{
	const std::string oldFilename = FileName;
	FileName = filename;
	GeometryArray curvegeo;
	bool res = ReadCurveData(&curvegeo);
	if(res) {
		const unsigned n = curvegeo.numGeometries();
		std::cout<<"\n bcc interface loading "<<n<<" curve geometries. ";
		unsigned i=0;
		for(;i<n;i++)
			world->addCurveGroup((CurveGroup *)curvegeo.geometry(i));
	}
	else {
		std::cout<<"\n hes file contains no curve geometry. ";
	}
	FileName = oldFilename;
	return res;
}
Exemple #7
0
bool AdeniumInterface::readTriangleMeshFromFile(AdeniumWorld * world)
{
    if(BaseFile::InvalidFilename(FileName)) 
		return false;
		
	if(!BaseFile::FileExists(FileName)) {
		FileName = "unknown";
		return false;
	}
    
    HesperisFile hes;
	hes.setReadComponent(HesperisFile::RTri);
	if(!hes.open(FileName)) return false;
	hes.close();
	
    GeometryArray triangleMeshes;
	hes.extractTriangleMeshes(&triangleMeshes);
    
    if(triangleMeshes.numGeometries() < 1) return false;
    std::cout<<" n tri mesh "<<triangleMeshes.numGeometries();
	
    world->addTriangleSystem(new BvhTriangleSystem((ATriangleMesh *)triangleMeshes.geometry(0)));
	return true;
}
Exemple #8
0
void BccInterface::testBlockMesh()
{
    BlockBccMeshBuilder builder;
    AOrientedBox box1;
    box1.setExtent(Vector3F(28.f, 14.f, 1.f));
    box1.setCenter(Vector3F(0.1f, -2.f, 1.f));
	
	AOrientedBox box2;
	Matrix33F rot; rot.set(Quaternion(0.f, 1.f, 0.f, .5f));
	box2.setOrientation(rot);
    box2.setExtent(Vector3F(18.f, 4.f, 1.f));
    box2.setCenter(Vector3F(2.1f, 13.f, -1.f));
	
	GeometryArray boxes;
	boxes.create(2);
	boxes.setGeometry(&box1, 0);
	boxes.setGeometry(&box2, 1);
	unsigned nv, nt, ns;
    builder.build(&boxes, nt, nv, ns);
	std::cout<<"\n tet nt nv ns "<<nt<<" "<<nv<<" "<<ns;
	m_tetMesh = new ATetrahedronMeshGroup;
	m_tetMesh->create(nv, nt, ns);
	builder.getResult(m_tetMesh);
}
Exemple #9
0
void KdCluster::leafWriteGroup(KdTreeNode *node, const BoundingBox & box)
{
	const unsigned num = node->getNumPrims();
	if(num < 1) return;
	
	m_groupGeometries[m_currentGroup] = new GeometryArray;
	
	GeometryArray * curGrp = m_groupGeometries[m_currentGroup];
	curGrp->create(num);
	
	unsigned start = node->getPrimStart();
	sdb::VectorArray<Primitive> &indir = indirection();
	//sdb::VectorArray<Primitive> &prims = primitives();
	int igeom, icomponent;
	unsigned igroup = 0;
	for(unsigned i = 0; i < num; i++) {
		//unsigned *iprim = indir[start + i];
		//Primitive * prim = prims.get(*iprim);
		Primitive * prim = indir[start + i];
		prim->getGeometryComponent(igeom, icomponent);
		Geometry * geo = m_stream.geometry(igeom);
		if(geo->type() == TGeometryArray) {
			GeometryArray * ga = (GeometryArray *)geo;
			Geometry * comp = ga->geometry(icomponent);
			
			BoundingBox comb = ga->calculateBBox(icomponent);

// do not add straddling geo			
			if(comb.getMax(0) <= box.getMax(0) && 
				comb.getMax(1) <= box.getMax(1) && 
				comb.getMax(2) <= box.getMax(2)) 
			{
				curGrp->setGeometry(comp, igroup);
				igroup++;
			}
		}
		else {
			std::cout<<" grouping only works with geometry arry.";
		}
		//indir.next();
	}
	
	curGrp->setNumGeometries(igroup);
	m_nodeGroupInd[node] = m_currentGroup;
	m_currentGroup++;
}
Exemple #10
0
bool BccInterface::saveWorld(BccWorld * world)
{
    if(world->numTetrahedronMeshes() < 1) {
        std::cout<<" no tetrahedron mesh to save";
        return false;
    }
    
	HesperisFile hes;
    if(!hes.open(FileName)) {
        
        GeometryArray * gmgeo = world->triangleGeometries();
        if(!gmgeo) {
            std::cout<<" no triangle mesh to save";
            return false;
        }
        
        hes.create(FileName);
        hes.setWriteComponent(HesperisFile::WTri);
        hes.addTriangleMesh("growmesh", (ATriangleMeshGroup *)gmgeo->geometry(0));
        hes.setDirty();
        hes.save();
	}
    
	hes.setWriteComponent(HesperisFile::WTetra);
	
	unsigned ntet, nvert, nstripe, nanchor;
	world->computeTetrahedronMeshStatistics(ntet, nvert, nstripe, nanchor);
	
	ATetrahedronMeshGroup * cm = new ATetrahedronMeshGroup;
	cm->create(nvert, ntet, nstripe);
	
	const unsigned n = world->numTetrahedronMeshes();
	
	ntet = 0;
	nvert = 0;
    nstripe = 0;
	unsigned i = 0;
	for(; i < n; i++) {
		ATetrahedronMeshGroup * imesh = world->tetrahedronMesh(i);
        cm->copyPointDrift(imesh->pointDrifts(), 
                              imesh->numStripes(), 
                              nstripe,
                              nvert);
        cm->copyIndexDrift(imesh->indexDrifts(), 
                              imesh->numStripes(), 
                              nstripe,
                              ntet*4);
        
		cm->copyStripe(imesh, nvert, ntet * 4);
		
		ntet += imesh->numTetrahedrons();
		nvert += imesh->numPoints();
        nstripe += imesh->numStripes();
	}
	float vlm = cm->calculateVolume();
	cm->setVolume(vlm);
	
	std::cout<<"\n combined all for save out ";
	cm->verbose();
	
	hes.addTetrahedron("tetra_c", cm);
	hes.setDirty();
	hes.save();
	hes.close();

	delete cm;
    
	return true;
}