0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / Prs3d / Prs3d_ToolCylinder.cxx
1 // Created on: 1995-07-27
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Prs3d_ToolCylinder.hxx>
18
19 #include <Graphic3d_ArrayOfTriangles.hxx>
20 #include <Poly_Array1OfTriangle.hxx>
21 #include <Prs3d_ToolQuadric.hxx>
22
23 //=======================================================================
24 //function : Constructor
25 //purpose  :
26 //=======================================================================
27 Prs3d_ToolCylinder::Prs3d_ToolCylinder (const Standard_Real    theBottomRad,
28                                         const Standard_Real    theTopRad,
29                                         const Standard_Real    theHeight,
30                                         const Standard_Integer theNbSlices,
31                                         const Standard_Integer theNbStacks)
32 : myBottomRadius (theBottomRad),
33   myTopRadius (theTopRad),
34   myHeight (theHeight)
35 {
36   myStacksNb = theNbStacks;
37   mySlicesNb = theNbSlices;
38 }
39
40 //=======================================================================
41 //function : Vertex
42 //purpose  :
43 //=======================================================================
44 gp_Pnt Prs3d_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Real theV)
45 {
46   const Standard_Real aU      = theU * M_PI * 2.0;
47   const Standard_Real aRadius = myBottomRadius + (myTopRadius - myBottomRadius) * theV;
48   return gp_Pnt (Cos (aU) * aRadius,
49                  Sin (aU) * aRadius,
50                  theV * myHeight);
51 }
52
53 //=======================================================================
54 //function : Add
55 //purpose  :
56 //=======================================================================
57 gp_Dir Prs3d_ToolCylinder::Normal (const Standard_Real theU, const Standard_Real /*theV*/)
58 {
59   const Standard_Real aU = theU * M_PI * 2.0;
60   return gp_Dir (Cos (aU) * myHeight,
61                  Sin (aU) * myHeight,
62                  myBottomRadius - myTopRadius);
63 }
64
65 //=======================================================================
66 //function : Perform
67 //purpose  :
68 //=======================================================================
69 Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolCylinder::Create (const Standard_Real    theBottomRad,
70                                                                const Standard_Real    theTopRad,
71                                                                const Standard_Real    theHeight,
72                                                                const Standard_Integer theNbSlices,
73                                                                const Standard_Integer theNbStacks,
74                                                                const gp_Trsf&         theTrsf)
75 {
76   Handle(Graphic3d_ArrayOfTriangles) anArray;
77   Prs3d_ToolCylinder aTool (theBottomRad, theTopRad, theHeight, theNbSlices, theNbStacks);
78   aTool.FillArray (anArray, theTrsf);
79   return anArray;
80 }