NCBI C++ ToolKit
object_3d.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: object_3d.cpp 93979 2021-06-11 12:54:56Z hurwitz $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Paul Thiessen
27 *
28 * File Description:
29 * holds 3d-objects - helix cylinders and strand bricks
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 
41 
43 
44 #include "object_3d.hpp"
45 #include "opengl_renderer.hpp"
46 #include "style_manager.hpp"
47 #include "structure_set.hpp"
48 #include "cn3d_tools.hpp"
49 
52 
53 
54 BEGIN_SCOPE(Cn3D)
55 
56 const int Object3D::VALUE_NOT_SET = -1;
57 const TGi Object3D::GI_NOT_SET = -1;
58 
59 Object3D::Object3D(StructureBase *parent, const CResidue_pntrs& residues) :
60  StructureBase(parent),
61  moleculeID(VALUE_NOT_SET), fromResidueID(VALUE_NOT_SET), toResidueID(VALUE_NOT_SET)
62 {
63  if (!residues.IsInterval() || residues.GetInterval().size() != 1) {
64  ERRORMSG("Object3D::Object3D() - can't handle this type of Residue-pntrs (yet)!");
65  return;
66  }
67 
68  const CResidue_interval_pntr& interval = residues.GetInterval().front().GetObject();
69  moleculeID = interval.GetMolecule_id().Get();
70  fromResidueID = interval.GetFrom().Get();
71  toResidueID = interval.GetTo().Get();
72 }
73 
74 static inline void ModelPoint2Vector(const CModel_space_point& msp, Vector *v)
75 {
76  v->x = msp.GetX();
77  v->y = msp.GetY();
78  v->z = msp.GetZ();
79  *v /= msp.GetScale_factor();
80 }
81 
82 Helix3D::Helix3D(StructureBase *parent, const CCylinder& cylinder, const CResidue_pntrs& residues) :
83  Object3D(parent, residues)
84 {
85  if (moleculeID == Object3D::VALUE_NOT_SET) return;
86 
88  ModelPoint2Vector(cylinder.GetAxis_top(), &Cterm);
89 }
90 
91 bool Helix3D::Draw(const AtomSet *data) const
92 {
93  if (!parentSet->renderer) {
94  ERRORMSG("Helix3D::Draw() - no renderer");
95  return false;
96  }
97 
98  // get object parent
99  const StructureObject *object;
100  if (!GetParentOfType(&object)) return false;
101 
102  // get Style
103  HelixStyle helixStyle;
104  if (!parentSet->styleManager->GetHelixStyle(object, *this, &helixStyle))
105  return false;
106 
107  // draw the Helix
108  if (helixStyle.style != StyleManager::eNotDisplayed)
109  parentSet->renderer->DrawHelix(Nterm, Cterm, helixStyle);
110 
111  return true;
112 }
113 
114 Strand3D::Strand3D(StructureBase *parent, const CBrick& brick, const CResidue_pntrs& residues) :
115  Object3D(parent, residues)
116 {
117  if (moleculeID == Object3D::VALUE_NOT_SET) return;
118 
119  Vector c1, c2;
120  ModelPoint2Vector(brick.GetCorner_000(), &c1);
121  ModelPoint2Vector(brick.GetCorner_011(), &c2);
122  Nterm = (c1 + c2) / 2;
123 
124  ModelPoint2Vector(brick.GetCorner_100(), &c1);
125  ModelPoint2Vector(brick.GetCorner_111(), &c2);
126  Cterm = (c1 + c2) / 2;
127 
128  ModelPoint2Vector(brick.GetCorner_010(), &c1);
129  ModelPoint2Vector(brick.GetCorner_000(), &c2);
130  unitNormal = c1 - c2;
132 }
133 
134 bool Strand3D::Draw(const AtomSet *data) const
135 {
136  if (!parentSet->renderer) {
137  ERRORMSG("Strand3D::Draw() - no renderer");
138  return false;
139  }
140 
141  // get object parent
142  const StructureObject *object;
143  if (!GetParentOfType(&object)) return false;
144 
145  // get Style
146  StrandStyle strandStyle;
147  if (!parentSet->styleManager->GetStrandStyle(object, *this, &strandStyle))
148  return false;
149 
150  // draw the Strand
151  if (strandStyle.style != StyleManager::eNotDisplayed)
153 
154  return true;
155 }
156 
157 END_SCOPE(Cn3D)
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CBrick –.
Definition: Brick.hpp:66
CCylinder –.
Definition: Cylinder.hpp:66
CModel_space_point –.
CResidue_interval_pntr –.
CResidue_pntrs –.
bool Draw(const AtomSet *data) const
Definition: object_3d.cpp:91
Helix3D(StructureBase *parent, const ncbi::objects::CCylinder &cylinder, const ncbi::objects::CResidue_pntrs &residues)
Definition: object_3d.cpp:82
Vector Cterm
Definition: object_3d.hpp:66
Vector Nterm
Definition: object_3d.hpp:66
static const TGi GI_NOT_SET
Definition: object_3d.hpp:52
int moleculeID
Definition: object_3d.hpp:53
static const int VALUE_NOT_SET
Definition: object_3d.hpp:51
int toResidueID
Definition: object_3d.hpp:53
int fromResidueID
Definition: object_3d.hpp:53
Object3D(StructureBase *parent, const ncbi::objects::CResidue_pntrs &residues)
Definition: object_3d.cpp:59
StyleManager::eDisplayStyle style
void DrawHelix(const Vector &Nterm, const Vector &Cterm, const HelixStyle &helixStyle)
void DrawStrand(const Vector &Nterm, const Vector &Cterm, const Vector &unitNormal, const StrandStyle &strandStyle)
Strand3D(StructureBase *parent, const ncbi::objects::CBrick &brick, const ncbi::objects::CResidue_pntrs &residues)
Definition: object_3d.cpp:114
bool Draw(const AtomSet *data) const
Definition: object_3d.cpp:134
Vector Cterm
Definition: object_3d.hpp:77
Vector unitNormal
Definition: object_3d.hpp:77
Vector Nterm
Definition: object_3d.hpp:77
StructureSet * parentSet
bool GetParentOfType(const T **ptr, bool warnIfNotFound=true) const
OpenGLRenderer * renderer
StyleManager * styleManager
bool GetStrandStyle(const StructureObject *object, const Strand3D &strand, StrandStyle *strandStyle) const
bool GetHelixStyle(const StructureObject *object, const Helix3D &helix, HelixStyle *helixStyle) const
double y
Definition: vector_math.hpp:47
double x
Definition: vector_math.hpp:47
double z
Definition: vector_math.hpp:47
void normalize(void)
#define ERRORMSG(stream)
Definition: cn3d_tools.hpp:86
Include a standard set of the NCBI C++ Toolkit most basic headers.
char data[12]
Definition: iconv.c:80
const TPrim & Get(void) const
Definition: serialbase.hpp:347
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
bool IsInterval(void) const
Check if variant Interval is selected.
const TInterval & GetInterval(void) const
Get the variant data.
const TAxis_bottom & GetAxis_bottom(void) const
Get the Axis_bottom member data.
Definition: Cylinder_.hpp:281
TZ GetZ(void) const
Get the Z member data.
TX GetX(void) const
Get the X member data.
const TCorner_100 & GetCorner_100(void) const
Get the Corner_100 member data.
Definition: Brick_.hpp:574
const TAxis_top & GetAxis_top(void) const
Get the Axis_top member data.
Definition: Cylinder_.hpp:251
const TCorner_000 & GetCorner_000(void) const
Get the Corner_000 member data.
Definition: Brick_.hpp:454
const TCorner_111 & GetCorner_111(void) const
Get the Corner_111 member data.
Definition: Brick_.hpp:664
TScale_factor GetScale_factor(void) const
Get the Scale_factor member data.
TY GetY(void) const
Get the Y member data.
const TTo & GetTo(void) const
Get the To member data.
const TCorner_011 & GetCorner_011(void) const
Get the Corner_011 member data.
Definition: Brick_.hpp:544
const TFrom & GetFrom(void) const
Get the From member data.
const TMolecule_id & GetMolecule_id(void) const
Get the Molecule_id member data.
const TCorner_010 & GetCorner_010(void) const
Get the Corner_010 member data.
Definition: Brick_.hpp:514
USING_SCOPE(objects)
static void ModelPoint2Vector(const CModel_space_point &msp, Vector *v)
Definition: object_3d.cpp:74
USING_NCBI_SCOPE
Definition: object_3d.cpp:50
Modified on Mon May 06 04:52:09 2024 by modify_doxy.py rev. 669887