mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-06-30 12:14:08 +03:00
0025129: Visualization - add interactive object for Points Cloud objects
This commit is contained in:
parent
f9823ea65a
commit
9598bbb67c
@ -367,7 +367,8 @@ is
|
||||
|
||||
---Category: General Objects
|
||||
class ConnectedInteractive; --signature 0
|
||||
class MultipleConnectedInteractive; --signature 1
|
||||
class MultipleConnectedInteractive; --signature 1
|
||||
imported PointCloud; --signature 2
|
||||
|
||||
---Category: DIMENSIONS AND RELATIONS
|
||||
|
||||
|
150
src/AIS/AIS_PointCloud.cxx
Normal file
150
src/AIS/AIS_PointCloud.cxx
Normal file
@ -0,0 +1,150 @@
|
||||
// Created on: 2014-08-13
|
||||
// Created by: Maxim GLIBIN
|
||||
// Copyright (c) 2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <AIS_PointCloud.hxx>
|
||||
#include <AIS_Drawer.hxx>
|
||||
|
||||
#include <Prs3d_Root.hxx>
|
||||
#include <Prs3d_Presentation.hxx>
|
||||
#include <Prs3d_PointAspect.hxx>
|
||||
|
||||
#include <PrsMgr_Presentations.hxx>
|
||||
#include <PrsMgr_ModedPresentation.hxx>
|
||||
|
||||
#include <Graphic3d_Group.hxx>
|
||||
#include <Graphic3d_AspectMarker3d.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(AIS_PointCloud, AIS_InteractiveObject)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(AIS_PointCloud, AIS_InteractiveObject)
|
||||
|
||||
IMPLEMENT_HARRAY1(AIS_ArrayOfPnt)
|
||||
|
||||
//==================================================
|
||||
// Function: AIS_PointCloud
|
||||
// Purpose : Constructor
|
||||
//==================================================
|
||||
AIS_PointCloud::AIS_PointCloud()
|
||||
: AIS_InteractiveObject()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetPoints
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
bool AIS_PointCloud::SetPoints (const Handle(Graphic3d_ArrayOfPoints)& thePoints)
|
||||
{
|
||||
if (thePoints.IsNull() || !thePoints->IsValid()) return false;
|
||||
myPoints = thePoints;
|
||||
return true;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetPoints
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
bool AIS_PointCloud::SetPoints (const Handle(AIS_ArrayOfPnt)& theCoords,
|
||||
const Handle(AIS_ArrayOfPnt)& theColors,
|
||||
const Standard_Boolean hasColors)
|
||||
{
|
||||
if (theCoords.IsNull() || theColors.IsNull()) return false;
|
||||
if (theCoords->Size() != theColors->Size()) return false;
|
||||
|
||||
Standard_Integer aNumPoints = theCoords->Size();
|
||||
|
||||
Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (aNumPoints, hasColors);
|
||||
Standard_Integer iter = 1;
|
||||
for (; iter <= aNumPoints; iter++)
|
||||
{
|
||||
anArrayOfPoints->AddVertex (theCoords->Value(iter));
|
||||
|
||||
gp_Pnt aColor = theColors->Value(iter);
|
||||
anArrayOfPoints->SetVertexColor (anArrayOfPoints->VertexNumber(),
|
||||
aColor.X(), aColor.Y(), aColor.Z());
|
||||
}
|
||||
myPoints = anArrayOfPoints;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AIS_PointCloud::SetColor (const Quantity_NameOfColor theColor)
|
||||
{
|
||||
SetColor (Quantity_Color(theColor));
|
||||
}
|
||||
|
||||
void AIS_PointCloud::SetColor (const Quantity_Color &theColor)
|
||||
{
|
||||
if (!myDrawer->HasPointAspect())
|
||||
{
|
||||
myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, theColor, 1.0));
|
||||
*myDrawer->PointAspect()->Aspect() = *myDrawer->Link()->PointAspect()->Aspect();
|
||||
}
|
||||
myDrawer->PointAspect()->SetColor (theColor);
|
||||
|
||||
hasOwnColor = Standard_True;
|
||||
myOwnColor = theColor;
|
||||
|
||||
Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
|
||||
|
||||
const Handle(Prs3d_Presentation)& aPrs = Presentations().Value (1).Presentation()->Presentation();
|
||||
|
||||
// Set aspect for presentation
|
||||
aPrs->SetPrimitivesAspect (aPointAspect);
|
||||
|
||||
const Handle(Graphic3d_Group)& aGroup = aPrs->Groups().First();
|
||||
|
||||
// Check if aspect of given type is set for the group,
|
||||
// because setting aspect for group with no already set aspect
|
||||
// can lead to loss of presentation data
|
||||
if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
|
||||
{
|
||||
aGroup->SetGroupPrimitivesAspect (aPointAspect);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Compute
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_PointCloud::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
|
||||
const Handle(Prs3d_Presentation)& aPresentation,
|
||||
const Standard_Integer /*aMode*/)
|
||||
{
|
||||
aPresentation->Clear();
|
||||
if (myPoints.IsNull() || !myPoints->IsValid()) return;
|
||||
|
||||
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
|
||||
|
||||
/************************************
|
||||
static Handle(Graphic3d_AspectMarker3d) PtA = new Graphic3d_AspectMarker3d();
|
||||
PtA->SetType(Aspect_TOM_POINT);
|
||||
PtA->SetScale(1.);
|
||||
Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
|
||||
TheGroup->SetPrimitivesAspect(PtA);
|
||||
Handle(Graphic3d_ArrayOfPoints) aPoint = new Graphic3d_ArrayOfPoints (1);
|
||||
aPoint->AddVertex (myComponent->X(),myComponent->Y(),myComponent->Z());
|
||||
TheGroup->AddPrimitiveArray (aPoint);
|
||||
******************************/
|
||||
|
||||
if (Attributes()->HasPointAspect())
|
||||
{
|
||||
aGroup->SetPrimitivesAspect (Attributes()->PointAspect()->Aspect());
|
||||
}
|
||||
aGroup->AddPrimitiveArray (myPoints);
|
||||
}
|
||||
|
||||
void AIS_PointCloud::ComputeSelection(const Handle(SelectMgr_Selection)& /*aSelection*/,
|
||||
const Standard_Integer /*aMode*/)
|
||||
{
|
||||
}
|
74
src/AIS/AIS_PointCloud.hxx
Normal file
74
src/AIS/AIS_PointCloud.hxx
Normal file
@ -0,0 +1,74 @@
|
||||
// Created on: 2014-08-13
|
||||
// Created by: Maxim GLIBIN
|
||||
// Copyright (c) 2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _AIS_PointCloud_HeaderFile
|
||||
#define _AIS_PointCloud_HeaderFile
|
||||
|
||||
#include <AIS.hxx>
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Macro.hxx>
|
||||
#include <Graphic3d_ArrayOfPoints.hxx>
|
||||
#include <NCollection_Handle.hxx>
|
||||
#include <NCollection_HArray1.hxx>
|
||||
|
||||
DEFINE_STANDARD_HANDLE (AIS_PointCloud, AIS_InteractiveObject)
|
||||
|
||||
NCOLLECTION_HARRAY1(AIS_ArrayOfPnt, gp_Pnt)
|
||||
|
||||
//! Interactive object for set of points.
|
||||
class AIS_PointCloud : public AIS_InteractiveObject
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Create point cloud.
|
||||
Standard_EXPORT AIS_PointCloud ();
|
||||
|
||||
//! Initializes construction of the point cloud from points.
|
||||
//! @param thePoints [in] the points.
|
||||
Standard_EXPORT bool SetPoints (const Handle(Graphic3d_ArrayOfPoints)& thePoints);
|
||||
|
||||
//! Sets the points.
|
||||
//! @param theCoords [in] the array of coordinates.
|
||||
//! @param theColors [in] the array of RGB colors.
|
||||
Standard_EXPORT bool SetPoints (const Handle(AIS_ArrayOfPnt)& theCoords,
|
||||
const Handle(AIS_ArrayOfPnt)& theColors,
|
||||
const Standard_Boolean hasColors = true);
|
||||
|
||||
//! Sets the color theColor in the reconstructed point cloud
|
||||
Standard_EXPORT void SetColor (const Quantity_NameOfColor theColor);
|
||||
Standard_EXPORT void SetColor (const Quantity_Color &theColor);
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTI (AIS_PointCloud)
|
||||
|
||||
protected:
|
||||
|
||||
Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
|
||||
const Handle(Prs3d_Presentation)& thePresentation,
|
||||
const Standard_Integer theMode = 0);
|
||||
|
||||
Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
|
||||
const Standard_Integer aMode);
|
||||
|
||||
private:
|
||||
|
||||
Handle(Graphic3d_ArrayOfPoints) myPoints;
|
||||
};
|
||||
|
||||
#endif // _AIS_PointCloud_HeaderFile
|
@ -21,3 +21,5 @@ AIS_DiameterDimension.hxx
|
||||
AIS_DiameterDimension.cxx
|
||||
AIS_RadiusDimension.hxx
|
||||
AIS_RadiusDimension.cxx
|
||||
AIS_PointCloud.hxx
|
||||
AIS_PointCloud.cxx
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <AIS_DisplayMode.hxx>
|
||||
#include <AIS_PointCloud.hxx>
|
||||
#include <TColStd_MapOfInteger.hxx>
|
||||
#include <AIS_MapOfInteractive.hxx>
|
||||
#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
|
||||
@ -5028,6 +5029,194 @@ static int VFont (Draw_Interpretor& theDI,
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : VPointCloud
|
||||
//purpose : Create interactive object for arbitary set of points.
|
||||
//=======================================================================
|
||||
static Standard_Integer VPointCloud (Draw_Interpretor&,
|
||||
Standard_Integer theArgNum,
|
||||
const char** theArgs)
|
||||
{
|
||||
if (theArgNum < 2)
|
||||
{
|
||||
std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help "
|
||||
<< theArgs[0] << "' for more information.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
|
||||
if (anAISContext.IsNull())
|
||||
{
|
||||
std::cerr << "Call 'vinit' before!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Standard_Integer anArgIter = 1;
|
||||
|
||||
// Get and check point cloud name in AIS context
|
||||
TCollection_AsciiString aName (theArgs[anArgIter++]);
|
||||
if (GetMapOfAIS().IsBound2 (aName))
|
||||
{
|
||||
std::cout << theArgs[0] << " error: object name exists." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Sets default value
|
||||
Standard_Integer aMode = 0;
|
||||
Standard_Integer aMarkerType = -1;
|
||||
Quantity_NameOfColor aColorName = Quantity_NOC_YELLOW;
|
||||
Standard_Real aScale = 1.;
|
||||
Standard_Boolean aHasColor = true;
|
||||
Standard_Integer aNumberOfPoints = 1000;
|
||||
TCollection_AsciiString aFileName = NULL;
|
||||
|
||||
// Parses arguments
|
||||
for (; anArgIter < theArgNum; ++anArgIter)
|
||||
{
|
||||
const TCollection_AsciiString anArg (theArgs[anArgIter]);
|
||||
if (anArg.Search ("Mode=") > -1)
|
||||
{
|
||||
aMode = anArg.Token ("=", 2).IntegerValue();
|
||||
if (aMode != 0 && aMode != 1)
|
||||
{
|
||||
std::cerr << "Wrong argument : " << anArg << "\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (anArg.Search ("MarkerType=") > -1)
|
||||
{
|
||||
aMarkerType = anArg.Token ("=", 2).IntegerValue();
|
||||
}
|
||||
else if (anArg.Search ("ColorName=") > -1)
|
||||
{
|
||||
aColorName = ViewerTest::GetColorFromName (anArg.Token ("=", 2).ToCString());
|
||||
aHasColor = false;
|
||||
}
|
||||
else if (anArg.Search ("Scale=") > -1)
|
||||
{
|
||||
aScale = anArg.Token ("=", 2).RealValue();
|
||||
}
|
||||
else if (anArg.Search ("NumPoints=") > -1)
|
||||
{
|
||||
aNumberOfPoints = anArg.Token ("=", 2).IntegerValue();
|
||||
}
|
||||
else if (anArg.Search ("FileName=") > -1)
|
||||
{
|
||||
aFileName = anArg.Token ("=", 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Wrong argument: " << anArg << "\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
srand (static_cast<unsigned int>(time(NULL)));
|
||||
|
||||
// Point cloud initialization
|
||||
Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
|
||||
|
||||
Standard_Integer anIter = 1;
|
||||
if (aMode == 0)
|
||||
{
|
||||
Handle(Graphic3d_ArrayOfPoints) anArrayPoints = new Graphic3d_ArrayOfPoints (aNumberOfPoints, aHasColor);
|
||||
for (; anIter < aNumberOfPoints; anIter++)
|
||||
{
|
||||
// Create random points
|
||||
gp_Pnt aPoint (RandomReal (0., 10000.),
|
||||
RandomReal (0., 10000.),
|
||||
RandomReal (0., 10000.));
|
||||
|
||||
// Create random colors
|
||||
Quantity_Color aColor (RandomReal (0., 1.),
|
||||
RandomReal (0., 1.),
|
||||
RandomReal (0., 1.),
|
||||
Quantity_TOC_RGB);
|
||||
|
||||
// Add point with color in array
|
||||
anArrayPoints->AddVertex (aPoint, aColor);
|
||||
}
|
||||
// Set array of points in point cloud object
|
||||
aPointCloud->SetPoints (anArrayPoints);
|
||||
}
|
||||
/*else if (aMode == 1)
|
||||
{
|
||||
Handle(AIS_ArrayOfPnt) aCoords = new AIS_ArrayOfPnt (1, aNumberOfPoints);
|
||||
Handle(AIS_ArrayOfPnt) aColors = new AIS_ArrayOfPnt (1, aNumberOfPoints);
|
||||
for (; anIter <= aNumberOfPoints; anIter++)
|
||||
{
|
||||
gp_Pnt aPoint (RandomReal (0., 5000.),
|
||||
RandomReal (0., 5000.),
|
||||
RandomReal (0., 5000.));
|
||||
aCoords->SetValue (anIter, aPoint);
|
||||
|
||||
gp_Pnt aColor (RandomReal (0., 1.),
|
||||
RandomReal (0., 1.),
|
||||
RandomReal (0., 1.));
|
||||
aColors->SetValue (anIter, aColor);
|
||||
}
|
||||
// Set coordinates and colors
|
||||
aPointCloud->SetPoints (aCoords, aColors, aHasColor);
|
||||
}*/
|
||||
|
||||
//std::cout << aPointCloud->Attributes()->HasLocalAttributes()
|
||||
|
||||
// Set point aspect for attributes of interactive object
|
||||
Aspect_TypeOfMarker anAMarkerType = aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT;
|
||||
aPointCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (anAMarkerType, aColorName, aScale));
|
||||
|
||||
anAISContext->Display (aPointCloud);
|
||||
GetMapOfAIS().Bind (aPointCloud, theArgs[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : VPointCloudSetColor
|
||||
//purpose : Sets the color for point cloud.
|
||||
//=======================================================================
|
||||
static Standard_Integer VPointCloudSetColor (Draw_Interpretor&,
|
||||
Standard_Integer theArgNum,
|
||||
const char** theArgs)
|
||||
{
|
||||
// Check arguments
|
||||
if (theArgNum < 3)
|
||||
{
|
||||
std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help "
|
||||
<< theArgs[0] << "' for more information.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check AIS context
|
||||
Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
|
||||
if (anAISContext.IsNull())
|
||||
{
|
||||
std::cerr << "Call 'vinit' before!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Standard_Integer anArgIter = 1;
|
||||
|
||||
// Find an interactive object in map of AIS context
|
||||
TCollection_AsciiString aName (theArgs[anArgIter++]);
|
||||
Handle(AIS_InteractiveObject) anInterObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
|
||||
if (anInterObject.IsNull())
|
||||
{
|
||||
std::cout << "Not an AIS interactive object!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get color name
|
||||
const TCollection_AsciiString aColorName (theArgs[anArgIter++]);
|
||||
Quantity_NameOfColor aNameOfColor = ViewerTest::GetColorFromName (aColorName.ToCString());
|
||||
|
||||
// Set color
|
||||
anInterObject->SetColor (aNameOfColor);
|
||||
|
||||
// Update context current viewer
|
||||
anAISContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ObjectsCommands
|
||||
//purpose :
|
||||
@ -5185,4 +5374,18 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
|
||||
"vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
|
||||
"\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
|
||||
__FILE__, VFont, group);
|
||||
|
||||
theCommands.Add ("vpointcloud",
|
||||
"vpointcloud usage:\n"
|
||||
"vpointcloud ObjectName [Mode=1]\n"
|
||||
" [NumPoints=100]\n"
|
||||
" [MarkerType=0] [ColorName=GREEN] [Scale=1.0]\n"
|
||||
" [FileName=PointCloudFile]"
|
||||
"\n\t\t: Create an interactive object for arbitary set of points.",
|
||||
__FILE__, VPointCloud, group);
|
||||
theCommands.Add ("vpcsetcolor",
|
||||
"vpcsetcolor usage:\n"
|
||||
"vpcsetcolor PointCloudObjectName [ColorName=GREEN]"
|
||||
"\n\t\t: Set color for point cloud interactive object.",
|
||||
__FILE__, VPointCloudSetColor, group);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user