Notice: If you are member of any public project or group, please make sure that your GitLab username is not the same as the LRZ identifier/Kennung (see https://gitlab.lrz.de/profile/account). Please change your username if necessary. For more information see the section "Public projects / Öffentliche Projekte" at https://doku.lrz.de/display/PUBLIC/GitLab . Thank you!

Commit 32f1e91d authored by Jakob Weiss's avatar Jakob Weiss

Added cylinders to GeometryDataFactory

* minor whitespace fix in mainwindow.cpp
parent 001aeb39
......@@ -363,7 +363,7 @@ namespace campvis {
void MainWindow::onBtnShowDataContainerInspectorClicked() {
if (_selectedPipeline != 0) {
// if there is no existing inspector window, create one
// if there is no existing inspector window, create one
if (_dcInspectorWindow == 0) {
_dcInspectorWindow = _mdiArea->addWidget(_dcInspectorWidget);
_dcInspectorWindow->setWindowTitle(tr("Data Container Inspector"));
......@@ -373,7 +373,7 @@ namespace campvis {
_dcInspectorWindow->show();
_dcInspectorWindow->activateWindow();
//_dcInspectorWindow->detachDockedWindow();
//_dcInspectorWindow->detachDockedWindow();
}
}
......
......@@ -398,4 +398,90 @@ namespace campvis {
return std::unique_ptr<MultiIndexedGeometry>(toReturn);
}
std::unique_ptr<MultiIndexedGeometry> GeometryDataFactory::createCylinder(uint16_t numSlices, float cylRadius)
{
cgtAssert(numSlices > 2, "Cylinder must have minimum 3 slices!");
std::vector<cgt::vec3> vertices;
std::vector<cgt::vec3> normals;
// add bottom vertex
vertices.push_back(cgt::vec3(0.f, 0.f, 0.f));
normals.push_back(cgt::vec3(0.f, 0.f, -1.f));
// add shaft floor vertices
for (int i = 0; i < numSlices; ++i) {
float theta = static_cast<float>(i) * 2.f*cgt::PIf / static_cast<float>(numSlices);
vertices.push_back(cgt::vec3(cylRadius * cos(theta), cylRadius * sin(theta), 0.f));
normals.push_back(cgt::vec3(0.f, 0.f, -1.f));
}
for (int i = 0; i < numSlices; ++i) {
float theta = static_cast<float>(i) * 2.f*cgt::PIf / static_cast<float>(numSlices);
vertices.push_back(cgt::vec3(cylRadius * cos(theta), cylRadius * sin(theta), 0.f));
normals.push_back(cgt::vec3(cos(theta), sin(theta), 0.f));
}
// add shaft top vertices
for (int i = 0; i < numSlices; ++i) {
float theta = static_cast<float>(i) * 2.f*cgt::PIf / static_cast<float>(numSlices);
vertices.push_back(cgt::vec3(cylRadius * cos(theta), cylRadius * sin(theta), 1.f));
normals.push_back(cgt::vec3(cos(theta), sin(theta), 0.f));
}
// add top center vertex
MultiIndexedGeometry::index_t topVertexIndex = vertices.size();
vertices.push_back(cgt::vec3(0.f, 0.f, 1.f));
normals.push_back(cgt::vec3(0.f, 0.f, 1.f));
// add rest of top vertices
for (int i = 0; i < numSlices; ++i) {
float theta = static_cast<float>(i) * 2.f*cgt::PIf / static_cast<float>(numSlices);
vertices.push_back(cgt::vec3(cylRadius * cos(theta), cylRadius * sin(theta), 1.f));
normals.push_back(cgt::vec3(0.f, 0.f, 1.f));
}
// create geometry
MultiIndexedGeometry* toReturn = new MultiIndexedGeometry(vertices, std::vector<cgt::vec3>(), std::vector<cgt::vec4>(), normals);
// add indices for primitives to geometry:
{
// cylinder floor
std::vector<MultiIndexedGeometry::index_t> indices;
for (MultiIndexedGeometry::index_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);
}
{
// cylinder shaft
std::vector<MultiIndexedGeometry::index_t> indices;
for (MultiIndexedGeometry::index_t j = 0; j < numSlices; ++j) {
indices.push_back(j + 1 + numSlices);
indices.push_back(j + 1 + numSlices * 2);
}
indices.push_back(1 + numSlices);
indices.push_back(1 + numSlices * 2);
toReturn->addPrimitive(indices);
}
{
// cylinder top
std::vector<MultiIndexedGeometry::index_t> indices;
for (MultiIndexedGeometry::index_t j = 0; j < numSlices; ++j) {
indices.push_back(topVertexIndex); // the last/top vertex
indices.push_back(topVertexIndex + j + 1);
}
indices.push_back(topVertexIndex); // the last/top vertex
indices.push_back(topVertexIndex + 1);
toReturn->addPrimitive(indices);
}
return std::unique_ptr<MultiIndexedGeometry>(toReturn);
}
}
\ No newline at end of file
......@@ -98,6 +98,14 @@ namespace campvis {
* \return MultiIndexedGeometry storing a unit arrow in Z direction starting from the origin.
*/
static std::unique_ptr<MultiIndexedGeometry> createArrow(uint16_t numSlices = 12, float tipLen = 0.35, float cylRadius = 0.05, float tipRadius = 0.15);
/**
* Creates an MultiIndexedGeometry storing a unit length cylinder in Z direction based on the origin
* \param numSlices Number of slices in the cylinder and cone
* \param cylRadius Radius of the cylinder (arrow shaft)
* \return MultiIndexedGeometry storing a unit arrow in Z direction starting from the origin.
*/
static std::unique_ptr<MultiIndexedGeometry> createCylinder(uint16_t numSlices = 12, float cylRadius = 0.05);
};
}
......
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