1 /* $Id: object_3d.cpp 103491 2007-05-04 17:18:18Z kazimird $
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
37 #include <objects/mmdb3/Residue_interval_pntr.hpp>
38 #include <objects/mmdb3/Model_space_point.hpp>
39 #include <objects/mmdb1/Molecule_id.hpp>
40 #include <objects/mmdb1/Residue_id.hpp>
41
42 #include "remove_header_conflicts.hpp"
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
50 USING_NCBI_SCOPE;
51 USING_SCOPE(objects);
52
53
54 BEGIN_SCOPE(Cn3D)
55
56 const int Object3D::VALUE_NOT_SET = -1;
57
Object3D(StructureBase * parent,const CResidue_pntrs & residues)58 Object3D::Object3D(StructureBase *parent, const CResidue_pntrs& residues) :
59 StructureBase(parent),
60 moleculeID(VALUE_NOT_SET), fromResidueID(VALUE_NOT_SET), toResidueID(VALUE_NOT_SET)
61 {
62 if (!residues.IsInterval() || residues.GetInterval().size() != 1) {
63 ERRORMSG("Object3D::Object3D() - can't handle this type of Residue-pntrs (yet)!");
64 return;
65 }
66
67 const CResidue_interval_pntr& interval = residues.GetInterval().front().GetObject();
68 moleculeID = interval.GetMolecule_id().Get();
69 fromResidueID = interval.GetFrom().Get();
70 toResidueID = interval.GetTo().Get();
71 }
72
ModelPoint2Vector(const CModel_space_point & msp,Vector * v)73 static inline void ModelPoint2Vector(const CModel_space_point& msp, Vector *v)
74 {
75 v->x = msp.GetX();
76 v->y = msp.GetY();
77 v->z = msp.GetZ();
78 *v /= msp.GetScale_factor();
79 }
80
Helix3D(StructureBase * parent,const CCylinder & cylinder,const CResidue_pntrs & residues)81 Helix3D::Helix3D(StructureBase *parent, const CCylinder& cylinder, const CResidue_pntrs& residues) :
82 Object3D(parent, residues)
83 {
84 if (moleculeID == Object3D::VALUE_NOT_SET) return;
85
86 ModelPoint2Vector(cylinder.GetAxis_bottom(), &Nterm);
87 ModelPoint2Vector(cylinder.GetAxis_top(), &Cterm);
88 }
89
Draw(const AtomSet * data) const90 bool Helix3D::Draw(const AtomSet *data) const
91 {
92 if (!parentSet->renderer) {
93 ERRORMSG("Helix3D::Draw() - no renderer");
94 return false;
95 }
96
97 // get object parent
98 const StructureObject *object;
99 if (!GetParentOfType(&object)) return false;
100
101 // get Style
102 HelixStyle helixStyle;
103 if (!parentSet->styleManager->GetHelixStyle(object, *this, &helixStyle))
104 return false;
105
106 // draw the Helix
107 if (helixStyle.style != StyleManager::eNotDisplayed)
108 parentSet->renderer->DrawHelix(Nterm, Cterm, helixStyle);
109
110 return true;
111 }
112
Strand3D(StructureBase * parent,const CBrick & brick,const CResidue_pntrs & residues)113 Strand3D::Strand3D(StructureBase *parent, const CBrick& brick, const CResidue_pntrs& residues) :
114 Object3D(parent, residues)
115 {
116 if (moleculeID == Object3D::VALUE_NOT_SET) return;
117
118 Vector c1, c2;
119 ModelPoint2Vector(brick.GetCorner_000(), &c1);
120 ModelPoint2Vector(brick.GetCorner_011(), &c2);
121 Nterm = (c1 + c2) / 2;
122
123 ModelPoint2Vector(brick.GetCorner_100(), &c1);
124 ModelPoint2Vector(brick.GetCorner_111(), &c2);
125 Cterm = (c1 + c2) / 2;
126
127 ModelPoint2Vector(brick.GetCorner_010(), &c1);
128 ModelPoint2Vector(brick.GetCorner_000(), &c2);
129 unitNormal = c1 - c2;
130 unitNormal.normalize();
131 }
132
Draw(const AtomSet * data) const133 bool Strand3D::Draw(const AtomSet *data) const
134 {
135 if (!parentSet->renderer) {
136 ERRORMSG("Strand3D::Draw() - no renderer");
137 return false;
138 }
139
140 // get object parent
141 const StructureObject *object;
142 if (!GetParentOfType(&object)) return false;
143
144 // get Style
145 StrandStyle strandStyle;
146 if (!parentSet->styleManager->GetStrandStyle(object, *this, &strandStyle))
147 return false;
148
149 // draw the Strand
150 if (strandStyle.style != StyleManager::eNotDisplayed)
151 parentSet->renderer->DrawStrand(Nterm, Cterm, unitNormal, strandStyle);
152
153 return true;
154 }
155
156 END_SCOPE(Cn3D)
157