2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 08793132 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

added GeometryDataFactory::createSphere()

parent 2ef197ac
......@@ -163,4 +163,74 @@ namespace campvis {
return toReturn;
}
MultiIndexedGeometry* GeometryDataFactory::createSphere(uint16_t numStacks /*= 6*/, uint16_t numSlices /*= 12*/) {
tgtAssert(numStacks > 1 && numSlices > 2, "Sphere must have minimum 2 stacks and 3 slices!");
std::vector<tgt::vec3> vertices;
// add top vertex
vertices.push_back(tgt::vec3(0.f, 0.f, 1.f));
// add middle vertices
for (int i = 1; i < numStacks; ++i) {
float phi = static_cast<float>(i) * tgt::PIf / static_cast<float>(numStacks);
for (int j = 0; j < numSlices; ++j) {
float theta = static_cast<float>(j) * 2.f*tgt::PIf / static_cast<float>(numSlices);
vertices.push_back(tgt::vec3(cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi)));
}
}
// add bottom vertex
vertices.push_back(tgt::vec3(0.f, 0.f, -1.f));
// create geometry (in a unit sphere vertices = normals)
MultiIndexedGeometry* toReturn = new MultiIndexedGeometry(vertices, std::vector<tgt::vec3>(), std::vector<tgt::vec4>(), vertices);
// add indices for primitives to geometry:
{
// top stack:
std::vector<uint16_t> indices;
for (uint16_t j = 0; j < numSlices; ++j) {
indices.push_back(0);
indices.push_back(j+1);
}
indices.push_back(0);
indices.push_back(1);
toReturn->addPrimitive(indices);
}
{
// middle stacks:
std::vector<uint16_t> indices;
for (uint16_t i = 1; i < numStacks-1; ++i) {
uint16_t startIndex = 1 + (i-1) * numSlices;
for (uint16_t j = 0; j < numSlices; ++j) {
indices.push_back(startIndex + j);
indices.push_back(startIndex + numSlices + j);
}
indices.push_back(startIndex);
indices.push_back(startIndex + numSlices);
}
toReturn->addPrimitive(indices);
}
{
// bottom stack:
std::vector<uint16_t> indices;
uint16_t endIndex = static_cast<uint16_t>(vertices.size() - 1);
for (uint16_t j = 0; j < numSlices; ++j) {
indices.push_back(endIndex);
indices.push_back(endIndex - (j+1));
}
indices.push_back(endIndex);
indices.push_back(endIndex - 1);
toReturn->addPrimitive(indices);
}
return toReturn;
}
}
\ No newline at end of file
......@@ -27,6 +27,7 @@
#include "tgt/bounds.h"
#include "tgt/vector.h"
#include "core/datastructures/geometrydata.h"
#include "core/datastructures/facegeometry.h"
#include "core/datastructures/meshgeometry.h"
......@@ -64,6 +65,14 @@ namespace campvis {
* \return MultiIndexedGeometry storing the famous Utah teapot.
*/
static MultiIndexedGeometry* createTeapot();
/**
* Creates an MultiIndexedGeometry storing a unit sphere around the origin.
* \param llf Number of stacks in the sphere
* \param urb Number of slices in the sphere
* \return MultiIndexedGeometry storing a unit sphere around the origin.
*/
static MultiIndexedGeometry* createSphere(uint16_t numStacks = 6, uint16_t numSlices = 12);
};
}
......
......@@ -38,7 +38,7 @@
#include "core/tools/quadrenderer.h"
namespace campvis {
static const GenericOption<SliceExtractor::SliceOrientation> compositingOptions[3] = {
static const GenericOption<SliceExtractor::SliceOrientation> sliceOrientationOptions[3] = {
GenericOption<SliceExtractor::SliceOrientation>("z", "XY Plane", SliceExtractor::XY_PLANE),
GenericOption<SliceExtractor::SliceOrientation>("y", "XZ Plane", SliceExtractor::XZ_PLANE),
GenericOption<SliceExtractor::SliceOrientation>("x", "YZ Plane", SliceExtractor::YZ_PLANE)
......@@ -50,7 +50,7 @@ namespace campvis {
: VisualizationProcessor(viewportSizeProp)
, p_sourceImageID("sourceImageID", "Input Image", "", DataNameProperty::READ, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_PROPERTIES)
, p_targetImageID("targetImageID", "Output Image", "", DataNameProperty::WRITE)
, p_sliceOrientation("SliceOrientation", "Slice Orientation", compositingOptions, 3)
, p_sliceOrientation("SliceOrientation", "Slice Orientation", sliceOrientationOptions, 3)
, p_xSliceNumber("XSliceNumber", "X Slice Number", 0, 0, 0)
, p_xSliceColor("XSliceColor", "X Slice Color", tgt::vec4(1.f, 0.f, 0.f, 1.f), tgt::vec4(0.f), tgt::vec4(1.f))
, p_ySliceNumber("YSliceNumber", "Y Slice Number", 0, 0, 0)
......
......@@ -99,7 +99,7 @@ namespace campvis {
/// \see AbstractProcessor::updateResult
virtual void updateResult(DataContainer& dataContainer);
/// \see AbstractProcessor::updateProperties
virtual void updateProperties(DataContainer& dc);
virtual void updateProperties(DataContainer& dataContainer);
void updateBorderGeometry();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment