/usr/include/sofa/component/engine/BoxROI.inl is in libsofa1-dev 1.0~beta4-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | /******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4 *
* (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
*******************************************************************************
* SOFA :: Modules *
* *
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#ifndef SOFA_COMPONENT_ENGINE_BOXROI_INL
#define SOFA_COMPONENT_ENGINE_BOXROI_INL
#if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
#pragma once
#endif
#include <sofa/component/engine/BoxROI.h>
#include <sofa/helper/gl/template.h>
#include <sofa/helper/gl/BasicShapes.h>
namespace sofa
{
namespace component
{
namespace engine
{
using namespace sofa::helper;
using namespace sofa::defaulttype;
using namespace core::objectmodel;
template <class DataTypes>
BoxROI<DataTypes>::BoxROI()
: boxes( initData(&boxes, "box", "Box defined by xmin,ymin,zmin, xmax,ymax,zmax") )
, f_X0( initData (&f_X0, "rest_position", "Rest position coordinates of the degrees of freedom") )
, f_indices( initData(&f_indices,"indices","Indices of the points contained in the ROI") )
, _drawSize( initData(&_drawSize,0.0,"drawSize","0 -> point based rendering") )
{
boxes.beginEdit()->push_back(Vec6(0,0,0,1,1,1));
boxes.endEdit();
addInput(&f_X0);
addOutput(&f_indices);
f_indices.beginEdit()->push_back(0);
f_indices.endEdit();
}
template <class DataTypes>
void BoxROI<DataTypes>::init()
{
if (!f_X0.isSet())
{
BaseData* parent = mstate->findField("rest_position");
f_X0.setParentValue(parent);
parent->addOutput(&f_X0);
f_X0.setReadOnly(true);
}
}
template <class DataTypes>
void BoxROI<DataTypes>::reinit()
{
update();
}
template <class DataTypes>
void BoxROI<DataTypes>::update()
{
dirty = false;
helper::vector<Vec6>& vb = *(boxes.beginEdit());
for (unsigned int bi=0;bi<vb.size();++bi)
{
if (vb[bi][0] > vb[bi][3]) std::swap(vb[bi][0],vb[bi][3]);
if (vb[bi][1] > vb[bi][4]) std::swap(vb[bi][1],vb[bi][4]);
if (vb[bi][2] > vb[bi][5]) std::swap(vb[bi][2],vb[bi][5]);
}
boxes.endEdit();
SetIndex& indices = *(f_indices.beginEdit());
indices.clear();
const VecCoord* x0 = &f_X0.getValue();
for( unsigned i=0; i<x0->size(); ++i )
{
Real x=0.0,y=0.0,z=0.0;
DataTypes::get(x,y,z,(*x0)[i]);
for (unsigned int bi=0;bi<vb.size();++bi)
{
const Vec6& b=vb[bi];
if( x >= b[0] && x <= b[3] && y >= b[1] && y <= b[4] && z >= b[2] && z <= b[5] )
{
indices.push_back(i);
break;
}
}
}
f_indices.endEdit();
}
template <class DataTypes>
void BoxROI<DataTypes>::draw()
{
if (!this->getContext()->getShowBehaviorModels())
return;
if( _drawSize.getValue() == 0) // old classical drawing by points
{
///draw the boxes
glBegin(GL_LINES);
const helper::vector<Vec6>& vb=boxes.getValue();
for (unsigned int bi=0;bi<vb.size();++bi)
{
const Vec6& b=vb[bi];
const Real& Xmin=b[0];
const Real& Xmax=b[3];
const Real& Ymin=b[1];
const Real& Ymax=b[4];
const Real& Zmin=b[2];
const Real& Zmax=b[5];
glVertex3d(Xmin,Ymin,Zmin);
glVertex3d(Xmin,Ymin,Zmax);
glVertex3d(Xmin,Ymin,Zmin);
glVertex3d(Xmax,Ymin,Zmin);
glVertex3d(Xmin,Ymin,Zmin);
glVertex3d(Xmin,Ymax,Zmin);
glVertex3d(Xmin,Ymax,Zmin);
glVertex3d(Xmax,Ymax,Zmin);
glVertex3d(Xmin,Ymax,Zmin);
glVertex3d(Xmin,Ymax,Zmax);
glVertex3d(Xmin,Ymax,Zmax);
glVertex3d(Xmin,Ymin,Zmax);
glVertex3d(Xmin,Ymin,Zmax);
glVertex3d(Xmax,Ymin,Zmax);
glVertex3d(Xmax,Ymin,Zmax);
glVertex3d(Xmax,Ymax,Zmax);
glVertex3d(Xmax,Ymin,Zmax);
glVertex3d(Xmax,Ymin,Zmin);
glVertex3d(Xmin,Ymax,Zmax);
glVertex3d(Xmax,Ymax,Zmax);
glVertex3d(Xmax,Ymax,Zmin);
glVertex3d(Xmax,Ymin,Zmin);
glVertex3d(Xmax,Ymax,Zmin);
glVertex3d(Xmax,Ymax,Zmax);
}
glEnd();
}
}
template <class DataTypes>
bool BoxROI<DataTypes>::addBBox(double* minBBox, double* maxBBox)
{
const helper::vector<Vec6>& vb=boxes.getValue();
for (unsigned int bi=0;bi<vb.size();++bi)
{
const Vec6& b=vb[bi];
if (b[0] < minBBox[0]) minBBox[0] = b[0];
if (b[1] < minBBox[1]) minBBox[1] = b[1];
if (b[2] < minBBox[2]) minBBox[2] = b[2];
if (b[3] > maxBBox[0]) maxBBox[0] = b[3];
if (b[4] > maxBBox[1]) maxBBox[1] = b[4];
if (b[5] > maxBBox[2]) maxBBox[2] = b[5];
}
return true;
}
} // namespace engine
} // namespace component
} // namespace sofa
#endif
|