+ add points view feature and command to triangulate it
This commit is contained in:
parent
7d96d0f0c8
commit
17d7dd840e
|
@ -33,6 +33,7 @@
|
|||
#include "PointsPy.h"
|
||||
#include "Properties.h"
|
||||
#include "PropertyPointKernel.h"
|
||||
#include "ViewFeature.h"
|
||||
|
||||
|
||||
/* registration table */
|
||||
|
@ -61,6 +62,7 @@ void PointsExport initPoints()
|
|||
// add data types
|
||||
Points::Feature ::init();
|
||||
Points::FeaturePython ::init();
|
||||
Points::ViewFeature ::init();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
|
|
@ -47,6 +47,8 @@ SET(Points_SRCS
|
|||
Properties.h
|
||||
PropertyPointKernel.cpp
|
||||
PropertyPointKernel.h
|
||||
ViewFeature.cpp
|
||||
ViewFeature.h
|
||||
)
|
||||
|
||||
add_library(Points SHARED ${Points_SRCS})
|
||||
|
|
88
src/Mod/Points/App/ViewFeature.cpp
Normal file
88
src/Mod/Points/App/ViewFeature.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
#include <vector>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
|
||||
#include "ViewFeature.h"
|
||||
|
||||
using namespace Points;
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// ViewFeature
|
||||
//===========================================================================
|
||||
/*
|
||||
import Points
|
||||
import random
|
||||
import math
|
||||
|
||||
r=random.Random()
|
||||
|
||||
p=Points.Points()
|
||||
pts=[]
|
||||
for i in range(21):
|
||||
for j in range(21):
|
||||
pts.append(App.Vector(i,j,r.gauss(5,0.05)))
|
||||
|
||||
p.addPoints(pts)
|
||||
doc=App.ActiveDocument
|
||||
pts=doc.addObject('Points::ViewFeature','View')
|
||||
pts.Points=p
|
||||
pts.Width=21
|
||||
pts.Height=21
|
||||
*/
|
||||
|
||||
PROPERTY_SOURCE(Points::ViewFeature, Points::Feature)
|
||||
|
||||
ViewFeature::ViewFeature()
|
||||
{
|
||||
App::PropertyType type = static_cast<App::PropertyType>(App::Prop_None);
|
||||
ADD_PROPERTY_TYPE(Width ,(0), "View", type, "The width of the point view");
|
||||
ADD_PROPERTY_TYPE(Height,(0), "View", type, "The height of the point view");
|
||||
ADD_PROPERTY_TYPE(Direction ,(Base::Vector3d(0,0,1)), "View", type, "The direction of the point view");
|
||||
|
||||
Width.StatusBits.set(2, true);
|
||||
Height.StatusBits.set(2, true);
|
||||
}
|
||||
|
||||
ViewFeature::~ViewFeature()
|
||||
{
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ViewFeature::execute(void)
|
||||
{
|
||||
int size = Height.getValue() * Width.getValue();
|
||||
if (size != Points.getValue().size())
|
||||
throw Base::ValueError("(Width * Height) doesn't match with number of points");
|
||||
this->Points.touch();
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
57
src/Mod/Points/App/ViewFeature.h
Normal file
57
src/Mod/Points/App/ViewFeature.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef POINTS_VIEW_FEATURE_H
|
||||
#define POINTS_VIEW_FEATURE_H
|
||||
|
||||
#include "PointsFeature.h"
|
||||
|
||||
|
||||
namespace Points
|
||||
{
|
||||
|
||||
/*! For the ViewFeature class it is expected that the Point property has Width*Height vertices
|
||||
and that with respect to their x,y coordinates they are ordered in a grid structure.
|
||||
If a point is marked invalid then one of its coordinates is set to NaN.
|
||||
*/
|
||||
class PointsExport ViewFeature : public Points::Feature
|
||||
{
|
||||
PROPERTY_HEADER(Points::ViewFeature);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ViewFeature(void);
|
||||
virtual ~ViewFeature(void);
|
||||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
//@}
|
||||
|
||||
App::PropertyInteger Width; /**< The width of the view. */
|
||||
App::PropertyInteger Height; /**< The height of the view. */
|
||||
App::PropertyVector Direction; /**< The direction of the view. */
|
||||
};
|
||||
|
||||
} //namespace Points
|
||||
|
||||
|
||||
#endif
|
|
@ -345,8 +345,8 @@ Mesh.show(m)
|
|||
int width;
|
||||
int height;
|
||||
|
||||
static char* kwds_greedy[] = {"Points", "Width", "Height", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|ii", kwds_greedy,
|
||||
static char* kwds_view[] = {"Points", "Width", "Height", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|ii", kwds_view,
|
||||
&(Points::PointsPy::Type), &pts,
|
||||
&width, &height))
|
||||
throw Py::Exception();
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Points/App/PointsFeature.h>
|
||||
#include <Mod/Points/App/ViewFeature.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
#include <Mod/Mesh/App/Core/Approximation.h>
|
||||
|
||||
|
@ -214,10 +214,63 @@ bool CmdPoissonReconstruction::isActive(void)
|
|||
return (hasActiveDocument() && !Gui::Control().activeDialog());
|
||||
}
|
||||
|
||||
DEF_STD_CMD_A(CmdViewTriangulation);
|
||||
|
||||
CmdViewTriangulation::CmdViewTriangulation()
|
||||
: Command("Reen_ViewTriangulation")
|
||||
{
|
||||
sAppModule = "Reen";
|
||||
sGroup = QT_TR_NOOP("Reverse Engineering");
|
||||
sMenuText = QT_TR_NOOP("View triangulation");
|
||||
sToolTipText = QT_TR_NOOP("View triangulation");
|
||||
sToolTipText = QT_TR_NOOP("View triangulation");
|
||||
sWhatsThis = "Reen_ViewTriangulation";
|
||||
}
|
||||
|
||||
void CmdViewTriangulation::activated(int iMsg)
|
||||
{
|
||||
std::vector<App::DocumentObject*> obj = Gui::Selection().getObjectsOfType(Points::ViewFeature::getClassTypeId());
|
||||
addModule(App,"ReverseEngineering");
|
||||
openCommand("View triangulation");
|
||||
try {
|
||||
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
|
||||
App::DocumentObjectT objT(*it);
|
||||
QString document = QString::fromStdString(objT.getDocumentPython());
|
||||
QString object = QString::fromStdString(objT.getObjectPython());
|
||||
|
||||
QString command = QString::fromLatin1("%1.addObject('Mesh::Feature', 'View mesh').Mesh = ReverseEngineering.viewTriangulation("
|
||||
"Points=%2.Points,"
|
||||
"Width=%2.Width,"
|
||||
"Height=%2.Height)"
|
||||
)
|
||||
.arg(document)
|
||||
.arg(object)
|
||||
;
|
||||
doCommand(Doc, command.toLatin1());
|
||||
}
|
||||
|
||||
commitCommand();
|
||||
updateActive();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
abortCommand();
|
||||
QMessageBox::warning(Gui::getMainWindow(),
|
||||
qApp->translate("Reen_ViewTriangulation", "View triangulation failed"),
|
||||
QString::fromLatin1(e.what())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool CmdViewTriangulation::isActive(void)
|
||||
{
|
||||
return Gui::Selection().countObjectsOfType(Points::ViewFeature::getClassTypeId()) > 0;
|
||||
}
|
||||
|
||||
void CreateReverseEngineeringCommands(void)
|
||||
{
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
rcCmdMgr.addCommand(new CmdApproxSurface());
|
||||
rcCmdMgr.addCommand(new CmdApproxPlane());
|
||||
rcCmdMgr.addCommand(new CmdPoissonReconstruction());
|
||||
rcCmdMgr.addCommand(new CmdViewTriangulation());
|
||||
}
|
||||
|
|
|
@ -60,7 +60,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
|||
|
||||
Gui::MenuItem *reconstruct = new Gui::MenuItem();
|
||||
reconstruct->setCommand("Surface reconstruction");
|
||||
*reconstruct << "Reen_PoissonReconstruction";
|
||||
*reconstruct << "Reen_PoissonReconstruction"
|
||||
<< "Reen_ViewTriangulation";
|
||||
*reen << reconstruct;
|
||||
|
||||
return root;
|
||||
|
|
Loading…
Reference in New Issue
Block a user