Exemplo n.º 1
0
void BoxTest::testGetters() {
	const Geometry::Box b1(-1.0f, 1.0f, -2.0f, 2.0f, -3.0f, 3.0f);
	const Geometry::Box b2;

	CPPUNIT_ASSERT(b1.getMaxX() == 1.0f);
	CPPUNIT_ASSERT(b1.getMax(Geometry::dimension_t::X) == 1.0f);
	CPPUNIT_ASSERT(b1.getMaxY() == 2.0f);
	CPPUNIT_ASSERT(b1.getMax(Geometry::dimension_t::Y) == 2.0f);
	CPPUNIT_ASSERT(b1.getMaxZ() == 3.0f);
	CPPUNIT_ASSERT(b1.getMax(Geometry::dimension_t::Z) == 3.0f);

	CPPUNIT_ASSERT(b1.getMinX() == -1.0f);
	CPPUNIT_ASSERT(b1.getMin(Geometry::dimension_t::X) == -1.0f);
	CPPUNIT_ASSERT(b1.getMinY() == -2.0f);
	CPPUNIT_ASSERT(b1.getMin(Geometry::dimension_t::Y) == -2.0f);
	CPPUNIT_ASSERT(b1.getMinZ() == -3.0f);
	CPPUNIT_ASSERT(b1.getMin(Geometry::dimension_t::Z) == -3.0f);

	CPPUNIT_ASSERT(b1.getExtentMax() == 6.0f);
	CPPUNIT_ASSERT(b1.getExtentMin() == 2.0f);

	CPPUNIT_ASSERT(b1.getExtentX() == 2.0f);
	CPPUNIT_ASSERT(b1.getExtent(Geometry::dimension_t::X) == 2.0f);
	CPPUNIT_ASSERT(b1.getExtentY() == 4.0f);
	CPPUNIT_ASSERT(b1.getExtent(Geometry::dimension_t::Y) == 4.0f);
	CPPUNIT_ASSERT(b1.getExtentZ() == 6.0f);
	CPPUNIT_ASSERT(b1.getExtent(Geometry::dimension_t::Z) == 6.0f);

	CPPUNIT_ASSERT(b1.getVolume() == 48.0f);
	CPPUNIT_ASSERT(b1.getSurfaceArea() == 88.0f);

	CPPUNIT_ASSERT(b1.getCenter() == Geometry::Vec3(0.0f, 0.0f, 0.0f));
	CPPUNIT_ASSERT(b1.getBoundingSphereRadius() == 0.5f * std::sqrt(56.0f));
}
Exemplo n.º 2
0
void drawBox(RenderingContext & rc, const Geometry::Box & box) {
	static Util::Reference<Mesh> mesh;
	if (mesh.isNull()) {
		VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		vertexDescription.appendNormalFloat();
		const Geometry::Box unitBox(Geometry::Vec3(-0.5f, -0.5f, -0.5f), Geometry::Vec3(0.5f, 0.5f, 0.5f));
		mesh = MeshUtils::MeshBuilder::createBox(vertexDescription, unitBox);
	}

	Geometry::Matrix4x4 matrix;
	matrix.translate(box.getCenter());
	matrix.scale(box.getExtentX(), box.getExtentY(), box.getExtentZ());
	rc.pushMatrix_modelToCamera();
	rc.multMatrix_modelToCamera(matrix);
	rc.displayMesh(mesh.get());
	rc.popMatrix_modelToCamera();
}
Exemplo n.º 3
0
void PolygonDensityEvaluator::calcPriority(Region * r)
{
	int testsPerAxis = getAttribute(Util::StringIdentifier("#Tests per axis"))->toUnsignedInt();
	Geometry::Box box = r->getBounds();

	PrioSplit px = calcPriority(Geometry::Helper::splitUpBox(box, testsPerAxis,1,1));
	PrioSplit py = calcPriority(Geometry::Helper::splitUpBox(box, 1,testsPerAxis,1));
	PrioSplit pz = calcPriority(Geometry::Helper::splitUpBox(box, 1,1,testsPerAxis));

	float volumePower = pow(box.getVolume(), getAttribute(Util::StringIdentifier("Volume Power"))->toFloat());
	px.prio *= volumePower;
	py.prio *= volumePower;
	pz.prio *= volumePower;

	float p = std::max(std::max(px.prio,py.prio),pz.prio);
	r->setAttribute(Util::StringIdentifier("PolygonDensityPrio"), GenericAttribute::createNumber<float>(p));

	float f = getAttribute(Util::StringIdentifier("Extent Power"))->toFloat();
	px.prio *= pow(box.getExtentX(),f);
	py.prio *= pow(box.getExtentY(),f);
	pz.prio *= pow(box.getExtentZ(),f);


	p = std::max(std::max(px.prio,py.prio),pz.prio);
	if(p==px.prio) {
		r->setAttribute(Util::StringIdentifier("PolygonDensitySplit"), GenericAttribute::createNumber<int>(0));
		r->setAttribute(Util::StringIdentifier("PolygonDensityRatio"), GenericAttribute::createNumber<float>(px.ratio));
	}
	else if(p==py.prio) {
		r->setAttribute(Util::StringIdentifier("PolygonDensitySplit"), GenericAttribute::createNumber<int>(1));
		r->setAttribute(Util::StringIdentifier("PolygonDensityRatio"), GenericAttribute::createNumber<float>(py.ratio));
	}
	else if(p==pz.prio) {
		r->setAttribute(Util::StringIdentifier("PolygonDensitySplit"), GenericAttribute::createNumber<int>(2));
		r->setAttribute(Util::StringIdentifier("PolygonDensityRatio"), GenericAttribute::createNumber<float>(pz.ratio));
	}
	else            FAIL();
}
Exemplo n.º 4
0
static void describeGeometryNode(ExporterContext & /*ctxt*/,DescriptionMap & desc, Node * node) {
	desc.setString(Consts::ATTR_NODE_TYPE, Consts::NODE_TYPE_GEOMETRY);

	std::unique_ptr<DescriptionMap> dataDesc(new DescriptionMap);

	GeometryNode * gn = dynamic_cast<GeometryNode*>(node);

	// annotate with bounding box
	const Geometry::Box bb = gn->getBB();
	const Geometry::Vec3 center = bb.getCenter();
	std::stringstream s;
	s << center.getX() << " " << center.getY() << " " << center.getZ() << " " << bb.getExtentX() << " " << bb.getExtentY() << " " << bb.getExtentZ();
	dataDesc->setString(Consts::ATTR_MESH_BB, s.str());

	Rendering::Mesh * m = gn->getMesh();
	if(m!=nullptr) { // mesh present?
		// no filename -> store data in .minsg
		if(m->getFileName().empty()) {
			std::ostringstream meshStream;
			if(Rendering::Serialization::saveMesh(gn->getMesh(), "mmf", meshStream)) {
				dataDesc->setString(Consts::ATTR_DATA_TYPE,"mesh");
				dataDesc->setString(Consts::ATTR_DATA_ENCODING,"base64");
				const std::string streamString = meshStream.str();
				const std::string meshString = Util::encodeBase64(std::vector<uint8_t>(streamString.begin(), streamString.end()));
				dataDesc->setString(Consts::DATA_BLOCK,meshString);
			}
		} else { // filename given?
			Util::FileName meshFilename(m->getFileName());

//			// make path to mesh relative to scene (if mesh lies below the scene)
//			Util::FileUtils::makeRelativeIfPossible(ctxt.sceneFile, meshFilename);

			dataDesc->setString(Consts::ATTR_DATA_TYPE,"mesh");
			dataDesc->setString(Consts::ATTR_MESH_FILENAME,meshFilename.toShortString());
		}
		ExporterTools::addDataEntry(desc, std::move(dataDesc));
	}

}