19 #include <QCoreApplication>
20 #include <QElapsedTimer>
21 #include <QProgressDialog>
46 std::ifstream fin(
filename.c_str(), std::ios::in);
50 while (fin.getline(line,
sizeof(line))) {
51 std::stringstream words(line);
56 P.
x =
static_cast<float>(atof(x.c_str()));
57 P.
y =
static_cast<float>(-atof(z.c_str()));
58 P.
z =
static_cast<float>(atof(y.c_str()));
59 point_cloud.push_back(P);
61 }
catch (
const std::bad_alloc&) {
74 std::vector<int>& offGroundIndexes,
80 static const double cloth_y_height = 0.05;
81 static const int clothbuffer = 2;
83 static const double gravity = 0.2;
95 bbMax.
y + cloth_y_height,
98 int width_num =
static_cast<int>(
floor((bbMax.
x - bbMin.
x) /
101 int height_num =
static_cast<int>(
floor((bbMax.
z - bbMin.
z) /
111 .arg(
timer.restart()));
124 QString(
"[CSF] Rasterization: %1 ms").arg(
timer.restart()));
130 QProgressDialog pDlg(parent);
131 pDlg.setWindowTitle(
"CSF");
132 pDlg.setLabelText(QString(
"Cloth deformation\n%1 x %2 particles")
137 QCoreApplication::processEvents();
139 bool wasCancelled =
false;
160 QCoreApplication::processEvents();
162 if (pDlg.wasCanceled()) {
169 QCoreApplication::processEvents();
173 QString(
"[CSF] Iterations: %1 ms").arg(
timer.restart()));
186 .arg(
timer.restart()));
193 groundIndexes, offGroundIndexes);
195 app->
dispToConsole(QString(
"[CSF] Distance computation: %1 ms")
196 .arg(
timer.restart()));
199 if (exportClothMesh) {
200 clothMesh = cloth.
toMesh();
204 }
catch (
const std::bad_alloc&) {
212 std::string filepath =
"terr_ground.txt";
216 std::ofstream f1(filepath, std::ios::out);
219 for (
size_t i = 0; i < grp.size(); i++) {
220 f1 << std::fixed << std::setprecision(8) << point_cloud[grp[i]].x <<
" "
221 << point_cloud[grp[i]].z <<
" " << -point_cloud[grp[i]].y
229 std::string filepath =
"off-ground points.txt";
233 std::ofstream f1(filepath, std::ios::out);
236 for (
size_t i = 0; i < grp.size(); i++) {
237 f1 << std::fixed << std::setprecision(8) << point_cloud[grp[i]].x <<
" "
238 << point_cloud[grp[i]].z <<
" " << -point_cloud[grp[i]].y
void saveGroundPoints(const std::vector< int > &grp, std::string path="")
CSF(wl::PointCloud &cloud)
bool do_filtering(std::vector< int > &groundIndexes, std::vector< int > &offGroundIndexes, bool exportClothMesh, ccMesh *&clothMesh, ecvMainAppInterface *app=0, QWidget *parent=0)
bool readPointsFromFile(std::string filename)
void saveOffGroundPoints(const std::vector< int > &grp, std::string path="")
void addForce(const Vec3 &direction)
std::vector< double > & getHeightvals()
ccMesh * toMesh() const
Converts the cloth to a CC mesh structure.
static bool Compute(const Cloth &cloth, const wl::PointCloud &pc, double class_threshold, std::vector< int > &groundIndexes, std::vector< int > &offGroundIndexes, unsigned N=3)
static bool RasterTerrain(Cloth &cloth, const wl::PointCloud &pc, std::vector< double > &heightVal, unsigned KNN=1)
Main application interface (for plugins)
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
void computeBoundingBox(Point &bbMin, Point &bbMax)
QTextStream & endl(QTextStream &stream)
static const std::string path
MiniVec< float, N > floor(const MiniVec< float, N > &a)