Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Conograph/trunk/src/utility_data_structure/TreeLattice.hh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations) (download) (as text)
Fri Feb 22 04:51:31 2013 UTC (11 years, 1 month ago) by rtomiyasu
File MIME type: text/x-c++hdr
File size: 7443 byte(s)


1 rtomiyasu 3 /*
2     * The MIT License
3    
4     Conograph (powder auto-indexing program)
5    
6     Copyright (c) <2012> <Ryoko Oishi-Tomiyasu, KEK>
7    
8     Permission is hereby granted, free of charge, to any person obtaining a copy
9     of this software and associated documentation files (the "Software"), to deal
10     in the Software without restriction, including without limitation the rights
11     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12     copies of the Software, and to permit persons to whom the Software is
13     furnished to do so, subject to the following conditions:
14    
15     The above copyright notice and this permission notice shall be included in
16     all copies or substantial portions of the Software.
17    
18     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24     THE SOFTWARE.
25     *
26     */
27     #ifndef _TreeLattice_hh_
28     #define _TreeLattice_hh_
29     // TreeLattice.hh
30    
31     #include <ostream>
32     #include <fstream>
33     #include <assert.h>
34    
35     #include "../RietveldAnalysisTypes.hh"
36     #include "NodeB.hh"
37     #include "VecDat3.hh"
38    
39     class TreeLattice
40     {
41     private:
42     // const Int4 m_data_type;
43    
44     NodeB* m_root; // K1, K2
45     NodeB* m_root_on_left; // K2, K3
46     NodeB* m_root_on_right; // K3, K1
47    
48     bool HeadIsTail;
49    
50     bool m_is_set_sort_criteria;
51     Int4 m_count_Q;
52     Double m_detS;
53    
54     // Returns 2 if HeadIsTail is true.
55     // Returns 1 if HeadIsTail is false, and m_root, m_root_on_left, m_root_on_right are not NULL.
56     // Returns 0 otherwise.
57     // inline Int4 SuperBasis() const;
58    
59     // Sets m_detS.
60     void setAreaSquare();
61     // Sets m_count_Q.
62     void setCountOfQ();
63    
64     public:
65     TreeLattice();
66     TreeLattice(const TreeLattice& rhs);
67     ~TreeLattice();
68    
69     inline const NodeB& Root() const;
70    
71     inline void setRoot(const Int4&, const Int4&);
72     inline void setRoot(const NodeB&, const NodeB&);
73    
74     inline void setRootEqualUpper();
75     inline void setRootOnLeftBranch(const NodeB& node);
76     inline void setRootOnRightBranch(const NodeB& node);
77    
78     inline void setSortingCriteria() { this->setCountOfQ(); this->setAreaSquare(); m_is_set_sort_criteria = true; };
79     inline Int4 putCountOfQ() const{ assert(m_is_set_sort_criteria); return m_count_Q; };
80     inline const Double& putAreaSquare() const{ assert(m_is_set_sort_criteria); return m_detS; };
81    
82     inline void swapBranch();
83    
84     TreeLattice& operator=(const TreeLattice& rhs);
85    
86     void clear();
87    
88     // On output, index_tray is sorted into ascending order, any elements are not repeated.
89     void putRootBuds(set<Bud>& tray) const;
90     void putBud(set<Bud>& tray) const;
91    
92     bool putQuadraticForm(SymMat<Double>& Q, multimap<Int4, VecDat3<Int4> >& qindex_hkl) const;
93    
94     void print(ostream&, const Double& minQ, const Double& maxQ) const;
95    
96     template <class Iterator>
97     static void print(const string&, const Iterator&, const Iterator&);
98     };
99    
100    
101     //inline Int4 TreeLattice::SuperBasis() const
102     //{
103     // if( HeadIsTail ) return 2;
104     // if( m_root != NULL && m_root_on_left != NULL && m_root_on_right != NULL ) return 1;
105     // return 0;
106     //}
107    
108    
109     inline const NodeB& TreeLattice::Root() const
110     {
111     if( m_root == NULL )
112     {
113     throw ZErrorMessage(ZErrorNullPointer, __FILE__, __LINE__, __FUNCTION__);
114     }
115     return *m_root;
116     }
117    
118    
119     inline void TreeLattice::setRoot(const Int4& K1, const Int4& K2)
120     {
121     this->clear();
122     m_root = new NodeB(K1, K2);
123     }
124    
125    
126     inline void TreeLattice::setRoot(const NodeB& lhs, const NodeB& rhs)
127     {
128     this->clear();
129     assert( lhs.Right() == rhs.Right() );
130    
131     m_root = new NodeB(lhs, rhs);
132     }
133    
134     inline void TreeLattice::setRootEqualUpper()
135     {
136     delete m_root_on_left;
137     m_root_on_left = NULL;
138     delete m_root_on_right;
139     m_root_on_right = NULL;
140    
141     if( m_root->IsBud() ) HeadIsTail = false;
142     else HeadIsTail = true;
143     m_is_set_sort_criteria = false;
144     }
145    
146     inline void TreeLattice::setRootOnLeftBranch(const NodeB& nodex)
147     {
148     assert( m_root != NULL );
149    
150     delete m_root_on_left;
151     m_root_on_left = NULL;
152    
153     if( nodex.Left() == m_root->Right() )
154     {
155     if( m_root_on_right == NULL )
156     {
157     HeadIsTail = false;
158     m_root_on_left = new NodeB(nodex);
159     m_root_on_right = new NodeB(m_root_on_left->Right(), m_root->Left());
160     }
161     else if( nodex.Right() == m_root_on_right->Left() )
162     {
163     m_root_on_left = new NodeB(nodex);
164     }
165     else assert( false );
166     }
167     else if( nodex.Right() == m_root->Right() )
168     {
169     if( m_root_on_right == NULL )
170     {
171     HeadIsTail = false;
172     m_root_on_left = new NodeB(nodex);
173     m_root_on_left->swapBranch();
174     m_root_on_right = new NodeB(m_root_on_left->Right(), m_root->Left());
175     }
176     else if( nodex.Left() == m_root_on_right->Left() )
177     {
178     m_root_on_left = new NodeB(nodex);
179     m_root_on_left->swapBranch();
180     }
181     else assert( false );
182     }
183     else assert( false );
184    
185     m_is_set_sort_criteria = false;
186     }
187    
188    
189     inline void TreeLattice::setRootOnRightBranch(const NodeB& nodex)
190     {
191     assert( m_root != NULL );
192    
193     delete m_root_on_right;
194     m_root_on_right = NULL;
195    
196     if( nodex.Right() == m_root->Left() )
197     {
198     if( m_root_on_left == NULL )
199     {
200     HeadIsTail = false;
201     m_root_on_right = new NodeB(nodex);
202     m_root_on_left = new NodeB(m_root->Right(), m_root_on_right->Left());
203     }
204     else if( nodex.Left() == m_root_on_left->Right() )
205     {
206     m_root_on_right = new NodeB(nodex);
207     }
208     else assert( false );
209     }
210     else if( nodex.Left() == m_root->Left() )
211     {
212     if( m_root_on_left == NULL )
213     {
214     HeadIsTail = false;
215     m_root_on_right = new NodeB(nodex);
216     m_root_on_right->swapBranch();
217     m_root_on_left = new NodeB(m_root->Right(), m_root_on_right->Left());
218     }
219     else if( nodex.Right() == m_root_on_left->Right() )
220     {
221     m_root_on_right = new NodeB(nodex);
222     m_root_on_right->swapBranch();
223     }
224     else assert( false );
225     }
226     else assert( false );
227    
228     m_is_set_sort_criteria = false;
229     }
230    
231    
232     inline bool operator<(const TreeLattice& lhs, const TreeLattice& rhs)
233     {
234     if( lhs.putCountOfQ() > rhs.putCountOfQ() ) return true;
235     if( lhs.putCountOfQ() < rhs.putCountOfQ() ) return false;
236     return lhs.putAreaSquare() < rhs.putAreaSquare();
237     }
238    
239     inline void TreeLattice::swapBranch()
240     {
241     if( m_root != NULL ) m_root->swapBranch();
242     swap(m_root_on_left, m_root_on_right);
243    
244     if( m_root_on_left != NULL ) m_root_on_left->swapBranch();
245     if( m_root_on_right != NULL ) m_root_on_right->swapBranch();
246     }
247    
248    
249    
250     template <class Iterator>
251     void TreeLattice::print(const string& fname,
252     const Iterator& it_begin, const Iterator& it_end)
253     {
254     const vector<QData>& qdata = VCData::putPeakQData();
255     const Double maxQ = qdata.rbegin()->q; // *max_element(Qdata.begin(), Qdata.end());
256     const Double minQ = qdata.begin()->q; // *min_element(Qdata.begin(), Qdata.end());
257    
258     ofstream ofs(fname.c_str());
259    
260     ofs << "** MaxQ = " << maxQ << endl;
261     ofs << "** MinQ = " << minQ << endl;
262     ofs << "**" << endl;
263    
264     // Output
265     Int4 index = 1;
266     for(Iterator it = it_begin; it!=it_end; it++)
267     {
268     ofs << "** Tree_" << index++ << endl;
269     it->print(ofs, minQ, maxQ);
270     ofs << endl;
271     }
272     }
273    
274    
275     #endif

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26