PLearn 0.1
BinaryBallTree.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // BinaryBallTree.cc
00004 //
00005 // Copyright (C) 2004 Pascal Lamblin 
00006 // 
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 // 
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 // 
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 // 
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 // 
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 /* *******************************************************      
00036  * $Id: BinaryBallTree.cc 6861 2007-04-09 19:04:15Z saintmlx $ 
00037  ******************************************************* */
00038 
00039 // Authors: Pascal Lamblin
00040 
00044 #include "BinaryBallTree.h"
00045 
00046 namespace PLearn {
00047 using namespace std;
00048 
00049 BinaryBallTree::BinaryBallTree() 
00050     : pivot( Vec() ),
00051       radius( 0 )
00052 {}
00053 
00054 PLEARN_IMPLEMENT_OBJECT( BinaryBallTree,
00055                          "Binary Tree, containing a point, a radius, and a set of points", 
00056                          "Each node of the tree contains the parameters of a ball :\n"
00057                          "a point and a radius.\n"
00058                          "Each leaf node contains a list of indices of points,\n"
00059                          "each non-leaf node has two children nodes.");
00060 
00061 void BinaryBallTree::declareOptions( OptionList& ol )
00062 {
00063     declareOption( ol, "pivot", &BinaryBallTree::pivot, OptionBase::buildoption,
00064                    "Center of the ball" );
00065 
00066     declareOption(ol, "radius", &BinaryBallTree::radius, OptionBase::buildoption,
00067                   "Radius of the ball" );
00068 
00069     declareOption(ol, "point_set", &BinaryBallTree::point_set, OptionBase::buildoption,
00070                   "List of indices of the points owned by this node (leaf only)" );
00071 
00072     declareOption(ol, "child1", &BinaryBallTree::child1, OptionBase::tuningoption,
00073                   "Pointer to first child (non-leaf only)" );
00074 
00075     declareOption(ol, "child2", &BinaryBallTree::child2, OptionBase::tuningoption,
00076                   "Pointer to second child (non-leaf only)" );
00077 
00078     // Now call the parent class' declareOptions
00079     inherited::declareOptions(ol);
00080 }
00081 
00082 void BinaryBallTree::build_()
00083 {
00084     if( child1 )
00085     { child1->parent = this; }
00086 
00087     if( child2 )
00088     { child2->parent = this; }
00089 }
00090 
00091 void BinaryBallTree::build()
00092 {
00093     inherited::build();
00094     build_();
00095 }
00096 
00097 void BinaryBallTree::setFirstChild( const BinBallTree& first_child )
00098 {
00099     this->child1 = first_child;
00100     if( first_child )
00101     {
00102         first_child->parent = this;
00103     }
00104 }
00105 
00106 void BinaryBallTree::setSecondChild( const BinBallTree& second_child )
00107 {
00108     this->child2 = second_child;
00109     if( second_child )
00110     {
00111         second_child->parent = this;
00112     }
00113 }
00114 
00115 BinBallTree BinaryBallTree::getFirstChild()
00116 {
00117     return this->child1;
00118 }
00119 
00120 BinBallTree BinaryBallTree::getSecondChild()
00121 {
00122     return this->child2;
00123 }
00124 
00125 BinaryBallTree* BinaryBallTree::getParent()
00126 {
00127     return this->parent;
00128 }
00129 
00130 void BinaryBallTree::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00131 {
00132     inherited::makeDeepCopyFromShallowCopy(copies);
00133 
00134     deepCopyField( child1, copies );
00135     deepCopyField( child2, copies );
00136     deepCopyField( pivot, copies );
00137     deepCopyField( point_set, copies );
00138 }
00139 
00140 } // end of namespace PLearn
00141 
00142 
00143 /*
00144   Local Variables:
00145   mode:c++
00146   c-basic-offset:4
00147   c-file-style:"stroustrup"
00148   c-file-offsets:((innamespace . 0)(inline-open . 0))
00149   indent-tabs-mode:nil
00150   fill-column:79
00151   End:
00152 */
00153 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines