1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

Merge remote branch 'origin/CR25129' into CR00000-HYDRO_3

This commit is contained in:
asl
2014-08-27 12:41:56 +04:00
6 changed files with 415 additions and 1 deletions

View File

@@ -368,6 +368,7 @@ is
---Category: General Objects ---Category: General Objects
class ConnectedInteractive; --signature 0 class ConnectedInteractive; --signature 0
class MultipleConnectedInteractive; --signature 1 class MultipleConnectedInteractive; --signature 1
imported PointCloud;
---Category: DIMENSIONS AND RELATIONS ---Category: DIMENSIONS AND RELATIONS

146
src/AIS/AIS_PointCloud.cxx Normal file
View File

@@ -0,0 +1,146 @@
// 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_Drawer.hxx>
#include <AIS_PointCloud.hxx>
#include <AIS_PointCloud.lxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Prs3d_PointAspect.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_Root.hxx>
#include <PrsMgr_ModedPresentation.hxx>
#include <PrsMgr_Presentations.hxx>
IMPLEMENT_STANDARD_HANDLE(AIS_PointCloud, AIS_InteractiveObject)
IMPLEMENT_STANDARD_RTTIEXT(AIS_PointCloud, AIS_InteractiveObject)
//==================================================
// Function: AIS_PointCloud
// Purpose : Constructor
//==================================================
AIS_PointCloud::AIS_PointCloud()
: AIS_InteractiveObject()
{
}
//=======================================================================
//function : SetPoints
//purpose :
//=======================================================================
void AIS_PointCloud::SetPoints (const Handle(Graphic3d_ArrayOfPoints)& thePoints)
{
myPoints.Nullify();
if (thePoints.IsNull())
return;
myPoints = thePoints;
}
//=======================================================================
//function : SetPoints
//purpose :
//=======================================================================
void AIS_PointCloud::SetPoints (const Handle(TColgp_HArray1OfPnt)& theCoords,
const Handle(Quantity_HArray1OfColor)& theColors)
{
myPoints.Nullify();
if (theCoords.IsNull())
return;
Standard_Integer aNumPoints = theCoords->Length();
Standard_Boolean aHasColors = Standard_False;
if (!theColors.IsNull() && aNumPoints == theColors->Length())
aHasColors = Standard_True;
myPoints = new Graphic3d_ArrayOfPoints (aNumPoints, aHasColors);
for (Standard_Integer aPntIter = theCoords->Lower(); aPntIter <= theCoords->Upper(); aPntIter++)
{
myPoints->AddVertex (theCoords->Value (aPntIter));
}
if (aHasColors)
{
Standard_Integer aNumVertex = 1;
for(Standard_Integer aColorIter = theColors->Lower(); aColorIter <= theColors->Upper(); aColorIter++)
{
myPoints->SetVertexColor (aNumVertex, theColors->Value (aColorIter));
aNumVertex++;
}
}
}
//=======================================================================
//function : SetColor
//purpose :
//=======================================================================
void AIS_PointCloud::SetColor (const Quantity_NameOfColor theColor)
{
SetColor (Quantity_Color (theColor));
}
//=======================================================================
//function : SetColor
//purpose :
//=======================================================================
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;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void AIS_PointCloud::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer /*theMode*/)
{
thePresentation->Clear();
if (GetPoints().IsNull() || !GetPoints()->IsValid())
return;
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
if (myDrawer->HasPointAspect())
{
aGroup->SetPrimitivesAspect (myDrawer->PointAspect()->Aspect());
}
aGroup->AddPrimitiveArray (GetPoints());
}
//=======================================================================
//function : ComputeSelection
//purpose :
//=======================================================================
void AIS_PointCloud::ComputeSelection(const Handle(SelectMgr_Selection)& /*theSelection*/,
const Standard_Integer /*theMode*/)
{
}

View File

@@ -0,0 +1,83 @@
// 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 <Graphic3d_ArrayOfPoints.hxx>
#include <Quantity_HArray1OfColor.hxx>
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Standard_Macro.hxx>
#include <TColgp_HArray1OfDir.hxx>
#include <TColgp_HArray1OfPnt.hxx>
DEFINE_STANDARD_HANDLE (AIS_PointCloud, AIS_InteractiveObject)
//! Interactive object for set of points.
class AIS_PointCloud : public AIS_InteractiveObject
{
public:
//! Constructor
Standard_EXPORT AIS_PointCloud ();
//! Sets the points from array of points.
//! @detailed This function allows to avoid data duplication.
//! @param thePoints [in] the array of points.
Standard_EXPORT virtual void SetPoints (const Handle(Graphic3d_ArrayOfPoints)& thePoints);
//! Sets the points with optional colors.
//! @param theCoords [in] the array of coordinates.
//! @param theColors [in] optional array of colors.
Standard_EXPORT virtual void SetPoints (const Handle(TColgp_HArray1OfPnt)& theCoords,
const Handle(Quantity_HArray1OfColor)& theColors = NULL);
//! Get the points.
//! @return the array of points.
Standard_EXPORT virtual const Handle(Graphic3d_ArrayOfPoints)& GetPoints () const;
//! Redefined method implemets the standard behavior.
Standard_EXPORT virtual void SetColor (const Quantity_NameOfColor theColor);
//! Redefined method implemets the standard behavior.
Standard_EXPORT virtual 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)& theSelection,
const Standard_Integer theMode);
private:
Handle(Graphic3d_ArrayOfPoints) myPoints;
};
#endif // _AIS_PointCloud_HeaderFile

View File

@@ -0,0 +1,19 @@
// Created on: 2014-08-25
// 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.
inline const Handle(Graphic3d_ArrayOfPoints)& AIS_PointCloud::GetPoints() const
{
return myPoints;
}

View File

@@ -21,3 +21,6 @@ AIS_DiameterDimension.hxx
AIS_DiameterDimension.cxx AIS_DiameterDimension.cxx
AIS_RadiusDimension.hxx AIS_RadiusDimension.hxx
AIS_RadiusDimension.cxx AIS_RadiusDimension.cxx
AIS_PointCloud.hxx
AIS_PointCloud.lxx
AIS_PointCloud.cxx

View File

@@ -39,6 +39,7 @@
#include <AIS_Shape.hxx> #include <AIS_Shape.hxx>
#include <AIS_DisplayMode.hxx> #include <AIS_DisplayMode.hxx>
#include <AIS_PointCloud.hxx>
#include <TColStd_MapOfInteger.hxx> #include <TColStd_MapOfInteger.hxx>
#include <AIS_MapOfInteractive.hxx> #include <AIS_MapOfInteractive.hxx>
#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
@@ -5028,6 +5029,159 @@ static int VFont (Draw_Interpretor& theDI,
return 0; return 0;
} }
//! Auxilarily function.
//! Create random float number in range from theMin to theMax.
static Standard_Real randomReal (const Standard_Real theMin, const Standard_Real theMax)
{
return theMin + (theMax - theMin) * Standard_Real(rand()) / RAND_MAX;
}
//=======================================================================
//function : VPointCloud
//purpose : Create interactive object for arbitary set of points.
//=======================================================================
static Standard_Integer VPointCloud (Draw_Interpretor& /*theDI*/,
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 point cloud object name
TCollection_AsciiString aName (theArgs[anArgIter++]);
// Sets default value
Standard_Integer aMode = 0;
Standard_Integer aMarkerType = -1;
Quantity_NameOfColor aColorName = Quantity_NOC_YELLOW;
Standard_Real aScale = 1.0;
Standard_Boolean aHasColor = Standard_True;
Standard_Integer aNumberOfPoints = 100;
// 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 << std::endl;
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 = Standard_False;
}
else if (anArg.Search ("Scale=") > -1)
{
aScale = anArg.Token ("=", 2).RealValue();
}
else if (anArg.Search ("NumPoints=") > -1)
{
aNumberOfPoints = anArg.Token ("=", 2).IntegerValue();
}
else
{
std::cerr << "Wrong argument: " << anArg << std::endl;
return 1;
}
}
// Point cloud initialization
Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
if (aMode == 0)
{
Handle(Graphic3d_ArrayOfPoints) anArrayPoints = new Graphic3d_ArrayOfPoints (aNumberOfPoints, aHasColor);
for (Standard_Integer anIter = 1; anIter < aNumberOfPoints; anIter++)
{
// Create random point
gp_Pnt aPoint (randomReal (0., 5000.),
randomReal (0., 5000.),
randomReal (0., 5000.));
// Create random color
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(TColgp_HArray1OfPnt) aCoords = new TColgp_HArray1OfPnt (1, aNumberOfPoints);
Handle(Quantity_HArray1OfColor) aColors = new Quantity_HArray1OfColor (1, aNumberOfPoints);
if (aCoords->Length() != aColors->Length())
{
std::cerr << "Wrong length of arrays" << std::endl;
return 1;
}
for (Standard_Integer aPntIt = aCoords->Lower(); aPntIt <= aCoords->Upper(); aPntIt++)
{
gp_Pnt aPoint (randomReal (0., 5000.),
randomReal (0., 5000.),
randomReal (0., 5000.));
aCoords->SetValue (aPntIt, aPoint);
}
if (aHasColor)
{
for (Standard_Integer aColorIt = aColors->Lower(); aColorIt <= aColors->Upper(); aColorIt++)
{
Quantity_Color aColor (randomReal (0., 1.),
randomReal (0., 1.),
randomReal (0., 1.),
Quantity_TOC_RGB);
aColors->SetValue (aColorIt, aColor);
}
}
else
{
aColors.Nullify();
}
// Set coordinates and colors
aPointCloud->SetPoints (aCoords, aColors);
}
// Set point aspect for attributes of interactive object
aPointCloud->Attributes()->SetPointAspect (
new Prs3d_PointAspect (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT,
aColorName,
aScale));
VDisplayAISObject (aName, aPointCloud);
return 0;
}
//======================================================================= //=======================================================================
//function : ObjectsCommands //function : ObjectsCommands
//purpose : //purpose :
@@ -5185,4 +5339,12 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
"vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]" "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
"\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]", "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
__FILE__, VFont, group); __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\t\t: Create an interactive object for arbitary set of points.",
__FILE__, VPointCloud, group);
} }