00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: InsideListExpression.cpp,v 1.7 2007/02/08 23:19:38 delpinux Exp $ 00019 00020 #include <InsideListExpression.hpp> 00021 00022 #include <Scene.hpp> 00023 #include <Object.hpp> 00024 #include <Union.hpp> 00025 #include <Intersection.hpp> 00026 #include <Not.hpp> 00027 00028 ReferenceCounting<Object> InsideListExpressionAnd::objects(const Scene& S) 00029 { 00030 Intersection* intersection = new Intersection(); 00031 00032 (*intersection).push_back((*__node1).objects(S)); 00033 (*intersection).push_back((*__node2).objects(S)); 00034 00035 return new Object(intersection); 00036 } 00037 00038 ReferenceCounting<Object> InsideListExpressionOr::objects(const Scene& S) 00039 { 00040 Union* merge = new Union(); 00041 00042 (*merge).push_back((*__node1).objects(S)); 00043 (*merge).push_back((*__node2).objects(S)); 00044 00045 return new Object(merge); 00046 } 00047 00048 00049 ReferenceCounting<Object> InsideListExpressionNot::objects(const Scene& S) 00050 { 00051 return new Object(new Not((*__node).objects(S))); 00052 } 00053 00054 ReferenceCounting<Object> InsideListExpressionLeaf::objects(const Scene& S) 00055 { 00056 Union* merge = new Union(); 00057 00058 TinyVector<3> reference = (*__leaf).reference(); 00059 00060 size_t numberOfLeafObjects = 0; 00061 for (size_t i = 0; i<S.nbObjects(); ++i) { 00062 if(S.object(i)->hasReference()) { 00063 if (S.object(i)->reference() == reference) { 00064 merge->push_back(S.object(i)); 00065 numberOfLeafObjects++; 00066 } 00067 } else { 00068 ffout(0) << "Object " << i << ':' << S.object(i) << "\nhas no reference\n\n"; 00069 } 00070 } 00071 00072 if (numberOfLeafObjects==0) { 00073 throw ErrorHandler(__FILE__,__LINE__, 00074 "no object has reference "+stringify(reference)+" in scene", 00075 ErrorHandler::normal); 00076 } 00077 00078 ConstReferenceCounting<Shape> leaves; 00079 if(numberOfLeafObjects == 1) { // leaf is just one object 00080 leaves = (*(*merge).begin())->shape(); 00081 } else { // leaves are an union 00082 leaves = merge; 00083 } 00084 00085 Object* o; 00086 if ((*__leaf).inside()) { 00087 o = new Object(leaves); 00088 } else { 00089 o = new Object(new Not(new Object(leaves))); 00090 } 00091 00092 o->setReference(reference); 00093 return o; 00094 } 00095
1.5.6