2016-09-27 04:59:06 -05:00
|
|
|
|
|
|
|
#include "cafBoxManipulatorGeometryGenerator.h"
|
|
|
|
|
|
|
|
#include "cvfBoxGenerator.h"
|
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfGeometryBuilderFaceList.h"
|
|
|
|
#include "cvfPrimitiveSetIndexedUInt.h"
|
|
|
|
|
|
|
|
using namespace cvf;
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
namespace caf
|
|
|
|
{
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
BoxManipulatorGeometryGenerator::BoxManipulatorGeometryGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
BoxManipulatorGeometryGenerator::~BoxManipulatorGeometryGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
void BoxManipulatorGeometryGenerator::setOrigin( const cvf::Vec3d& origin )
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
|
|
|
m_origin = origin;
|
|
|
|
|
|
|
|
m_vertices = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
void BoxManipulatorGeometryGenerator::setSize( const cvf::Vec3d& size )
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
|
|
|
m_size = size;
|
|
|
|
|
|
|
|
m_vertices = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::ref<cvf::DrawableGeo> BoxManipulatorGeometryGenerator::createBoundingBoxMeshDrawable()
|
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( m_vertices.isNull() )
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
|
|
|
calculateArrays();
|
|
|
|
}
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( !( m_vertices.notNull() && m_vertices->size() != 0 ) ) return nullptr;
|
2016-09-27 04:59:06 -05:00
|
|
|
|
|
|
|
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
2020-06-19 00:53:59 -05:00
|
|
|
geo->setVertexArray( m_vertices.p() );
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
cvf::ref<cvf::UIntArray> indices = lineIndicesFromQuadVertexArray( m_vertices.p() );
|
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> prim = new cvf::PrimitiveSetIndexedUInt( cvf::PT_LINES );
|
|
|
|
prim->setIndices( indices.p() );
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
geo->addPrimitiveSet( prim.p() );
|
2016-09-27 04:59:06 -05:00
|
|
|
|
|
|
|
return geo;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void BoxManipulatorGeometryGenerator::calculateArrays()
|
|
|
|
{
|
|
|
|
BoxGenerator gen;
|
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
cvf::Vec3d min = m_origin;
|
|
|
|
cvf::Vec3d max = m_origin + m_size;
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
gen.setMinMax( min, max );
|
|
|
|
gen.setSubdivisions( 1, 1, 1 );
|
2016-09-27 04:59:06 -05:00
|
|
|
GeometryBuilderFaceList builder;
|
2020-06-19 00:53:59 -05:00
|
|
|
gen.generate( &builder );
|
|
|
|
|
2016-09-27 04:59:06 -05:00
|
|
|
m_vertices = builder.vertices();
|
|
|
|
|
|
|
|
// TODO: Rotate generated vertices
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-09-27 04:59:06 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
cvf::ref<cvf::UIntArray> BoxManipulatorGeometryGenerator::lineIndicesFromQuadVertexArray( const cvf::Vec3fArray* vertexArray )
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
CVF_ASSERT( vertexArray );
|
2016-09-27 04:59:06 -05:00
|
|
|
|
|
|
|
size_t numVertices = vertexArray->size();
|
2020-06-19 00:53:59 -05:00
|
|
|
int numQuads = static_cast<int>( numVertices / 4 );
|
|
|
|
CVF_ASSERT( numVertices % 4 == 0 );
|
2016-09-27 04:59:06 -05:00
|
|
|
|
|
|
|
cvf::ref<cvf::UIntArray> indices = new cvf::UIntArray;
|
2020-06-19 00:53:59 -05:00
|
|
|
indices->resize( numQuads * 8 );
|
2016-09-27 04:59:06 -05:00
|
|
|
|
|
|
|
#pragma omp parallel for
|
2020-06-19 00:53:59 -05:00
|
|
|
for ( int i = 0; i < numQuads; i++ )
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
|
|
|
int idx = 8 * i;
|
2020-06-19 00:53:59 -05:00
|
|
|
indices->set( idx + 0, i * 4 + 0 );
|
|
|
|
indices->set( idx + 1, i * 4 + 1 );
|
|
|
|
indices->set( idx + 2, i * 4 + 1 );
|
|
|
|
indices->set( idx + 3, i * 4 + 2 );
|
|
|
|
indices->set( idx + 4, i * 4 + 2 );
|
|
|
|
indices->set( idx + 5, i * 4 + 3 );
|
|
|
|
indices->set( idx + 6, i * 4 + 3 );
|
|
|
|
indices->set( idx + 7, i * 4 + 0 );
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return indices;
|
|
|
|
}
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
} // namespace caf
|