Add outline rendering.

This commit is contained in:
James Grogan 2022-11-18 09:43:22 +00:00
parent f04d86e0ad
commit a20c0183df
20 changed files with 291 additions and 64 deletions

View file

@ -1,18 +1,16 @@
#include "MeshPrimitives.h"
#include "MeshBuilder.h"
#include <iostream>
std::unique_ptr<TriMesh> MeshPrimitives::build(const Rectangle& rectangle)
std::unique_ptr<TriMesh> MeshPrimitives::buildRectangleAsTriMesh()
{
const auto bottom_left = rectangle.getLocation();
const auto width = rectangle.getWidth();
const auto height = rectangle.getHeight();
VecPoints locations = {
bottom_left,
Point(bottom_left, width, 0),
Point(bottom_left, width, height),
Point(bottom_left, 0, height)
{0, 0},
{1, 0},
{1, 1},
{0, 1}
};
EdgeIds edge_ids = {
@ -31,14 +29,33 @@ std::unique_ptr<TriMesh> MeshPrimitives::build(const Rectangle& rectangle)
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
}
std::unique_ptr<TriMesh> MeshPrimitives::buildExplodedGrid(unsigned numX, unsigned numY)
std::unique_ptr<LineMesh> MeshPrimitives::buildRectangleAsLineMesh()
{
VecPoints locations = {
{0, 0},
{1, 0},
{1, 1},
{0, 1}
};
EdgeIds edge_ids = {
{0, 1},
{1, 2},
{2, 3},
{3, 0}
};
return MeshBuilder::buildLineMesh(locations, edge_ids);
}
std::unique_ptr<TriMesh> MeshPrimitives::buildExplodedGridAsTriMesh(unsigned numX, unsigned numY)
{
double delta_x = 1.0/double(numX);
double delta_y = 1.0/double(numY);
VecPoints locations (4 * numX * numY);
double offset_x = delta_x;
double offset_y = delta_y;
double offset_x = delta_x/2.0;
double offset_y = delta_y/2.0;
for (unsigned idx=0; idx<numY; idx++)
{
for(unsigned jdx=0; jdx<numX; jdx++)
@ -53,9 +70,10 @@ std::unique_ptr<TriMesh> MeshPrimitives::buildExplodedGrid(unsigned numX, unsign
locations[id_offset + 1] = Point(locX1, locY0);
locations[id_offset + 2] = Point(locX1, locY1);
locations[id_offset + 3] = Point(locX0, locY1);
offset_x += delta_x;
}
offset_x = delta_x;
offset_x = delta_x/2.0;
offset_y += delta_y;
}
@ -88,3 +106,49 @@ std::unique_ptr<TriMesh> MeshPrimitives::buildExplodedGrid(unsigned numX, unsign
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
}
std::unique_ptr<LineMesh> MeshPrimitives::buildExplodedGridAsLineMesh(unsigned numX, unsigned numY)
{
double delta_x = 1.0/double(numX);
double delta_y = 1.0/double(numY);
VecPoints locations (4 * numX * numY);
double offset_x = delta_x/2.0;
double offset_y = delta_y/2.0;
for (unsigned idx=0; idx<numY; idx++)
{
for(unsigned jdx=0; jdx<numX; jdx++)
{
auto locX0 = offset_x - delta_x/2.0;
auto locX1 = offset_x + delta_x/2.0;
auto locY0 = offset_y - delta_y/2.0;
auto locY1 = offset_y + delta_y/2.0;
auto id_offset = 4* (jdx + numX*idx);
locations[id_offset] = Point(locX0, locY0);
locations[id_offset + 1] = Point(locX1, locY0);
locations[id_offset + 2] = Point(locX1, locY1);
locations[id_offset + 3] = Point(locX0, locY1);
offset_x += delta_x;
}
offset_x = delta_x/2.0;
offset_y += delta_y;
}
EdgeIds edge_ids(4 * numX * numY);
for (unsigned idx=0; idx<numY; idx++)
{
for(unsigned jdx=0; jdx<numX; jdx++)
{
unsigned node_offset = 4 * (jdx + numX * idx);
auto id_offset = 4* (jdx + numX*idx);
edge_ids[id_offset] = {node_offset, node_offset + 1};
edge_ids[id_offset + 1] = {node_offset + 1, node_offset + 2};
edge_ids[id_offset + 2] = {node_offset + 2, node_offset + 3};
edge_ids[id_offset + 3] = {node_offset + 3, node_offset};
}
}
return MeshBuilder::buildLineMesh(locations, edge_ids);
}