Changes in / [980dd6:e6317b]
- Location:
- src
- Files:
-
- 5 added
- 165 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/Action.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <string> … … 15 17 using namespace std; 16 18 19 Action::state_ptr getEmptyState() { 20 return Action::state_ptr(Memory::ignore(new ActionState())); 21 } 22 17 23 // An empty state to indicate success 18 Action::state_ptr Action::success = Action::state_ptr(Memory::ignore(new ActionState()));19 Action::state_ptr Action::failure = Action::state_ptr(Memory::ignore(new ActionState()));24 Action::state_ptr Action::success = getEmptyState(); 25 Action::state_ptr Action::failure = getEmptyState(); 20 26 21 27 Action::Action(std::string _name,bool _doRegister) : -
src/Actions/ActionHistory.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "ActionHistory.hpp" -
src/Actions/ActionRegistry.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/ActionRegistry.hpp" -
src/Actions/ActionSequence.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/ActionSequence.hpp" -
src/Actions/AnalysisAction/MolecularVolumeAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/AnalysisAction/MolecularVolumeAction.hpp" -
src/Actions/AnalysisAction/PairCorrelationAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/AnalysisAction/PairCorrelationAction.hpp" -
src/Actions/AnalysisAction/PrincipalAxisSystemAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp" -
src/Actions/AtomAction/AddAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/AtomAction/AddAction.hpp" -
src/Actions/AtomAction/ChangeElementAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/AtomAction/ChangeElementAction.hpp" -
src/Actions/AtomAction/RemoveAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/AtomAction/RemoveAction.hpp" -
src/Actions/CmdAction/BondLengthTableAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/CmdAction/BondLengthTableAction.hpp" -
src/Actions/CmdAction/ElementDbAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/CmdAction/ElementDbAction.hpp" -
src/Actions/CmdAction/FastParsingAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/CmdAction/FastParsingAction.hpp" -
src/Actions/CmdAction/HelpAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/CmdAction/HelpAction.hpp" -
src/Actions/CmdAction/VerboseAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/CmdAction/VerboseAction.hpp" -
src/Actions/CmdAction/VersionAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/CmdAction/VersionAction.hpp" -
src/Actions/ErrorAction.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> -
src/Actions/FragmentationAction/DepthFirstSearchAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/FragmentationAction/DepthFirstSearchAction.hpp" -
src/Actions/FragmentationAction/FragmentationAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/FragmentationAction/FragmentationAction.hpp" -
src/Actions/FragmentationAction/SubgraphDissectionAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/FragmentationAction/SubgraphDissectionAction.hpp" -
src/Actions/MakroAction.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <string> -
src/Actions/ManipulateAtomsProcess.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "ManipulateAtomsProcess.hpp" -
src/Actions/MapOfActions.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 using namespace std; -
src/Actions/MethodAction.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> -
src/Actions/MoleculeAction/BondFileAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/BondFileAction.hpp" -
src/Actions/MoleculeAction/ChangeNameAction.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/ChangeNameAction.hpp" -
src/Actions/MoleculeAction/FillWithMoleculeAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/FillWithMoleculeAction.hpp" -
src/Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp" -
src/Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp" -
src/Actions/MoleculeAction/SaveAdjacencyAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/SaveAdjacencyAction.hpp" -
src/Actions/MoleculeAction/SaveBondsAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/SaveBondsAction.hpp" -
src/Actions/MoleculeAction/SaveTemperatureAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/SaveTemperatureAction.hpp" -
src/Actions/MoleculeAction/SuspendInWaterAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/SuspendInWaterAction.hpp" -
src/Actions/MoleculeAction/TranslateAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/TranslateAction.hpp" -
src/Actions/MoleculeAction/VerletIntegrationAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/MoleculeAction/VerletIntegrationAction.hpp" -
src/Actions/ParserAction/LoadXyzAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/ParserAction/LoadXyzAction.hpp" -
src/Actions/ParserAction/SaveXyzAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/ParserAction/SaveXyzAction.hpp" -
src/Actions/Process.cpp
r980dd6 re6317b 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 9 8 10 #include "Process.hpp" 9 11 … … 11 13 12 14 Process::Process(int _maxSteps, std::string _name, bool _doRegister) : 15 Observable("Process"), 13 16 Action(_name,_doRegister), 14 17 maxSteps(_maxSteps), -
src/Actions/TesselationAction/ConvexEnvelopeAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/TesselationAction/ConvexEnvelopeAction.hpp" -
src/Actions/TesselationAction/NonConvexEnvelopeAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp" -
src/Actions/WorldAction/AddEmptyBoundaryAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/AddEmptyBoundaryAction.hpp" -
src/Actions/WorldAction/BoundInBoxAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/BoundInBoxAction.hpp" -
src/Actions/WorldAction/CenterInBoxAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/CenterInBoxAction.hpp" -
src/Actions/WorldAction/CenterOnEdgeAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/CenterOnEdgeAction.hpp" -
src/Actions/WorldAction/ChangeBoxAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/ChangeBoxAction.hpp" -
src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp" -
src/Actions/WorldAction/RepeatBoxAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/RepeatBoxAction.hpp" -
src/Actions/WorldAction/ScaleBoxAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/ScaleBoxAction.hpp" -
src/Actions/WorldAction/SetDefaultNameAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/SetDefaultNameAction.hpp" -
src/Actions/WorldAction/SetGaussianBasisAction.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Actions/WorldAction/SetGaussianBasisAction.hpp" -
src/CommandLineParser.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <boost/program_options.hpp> -
src/Descriptors/AtomDescriptor.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Descriptors/AtomDescriptor.hpp" -
src/Descriptors/AtomIdDescriptor.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "AtomIdDescriptor.hpp" -
src/Descriptors/AtomTypeDescriptor.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Descriptors/AtomTypeDescriptor.hpp" -
src/Descriptors/MoleculeDescriptor.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Descriptors/MoleculeDescriptor.hpp" -
src/Descriptors/MoleculeIdDescriptor.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "MoleculeIdDescriptor.hpp" -
src/Descriptors/MoleculePtrDescriptor.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "MoleculePtrDescriptor.hpp" -
src/Exceptions/CustomException.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "CustomException.hpp" -
src/Exceptions/LinearDependenceException.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "LinearDependenceException.hpp" -
src/Exceptions/MathException.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "MathException.hpp" -
src/Exceptions/ZeroVectorException.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "ZeroVectorException.hpp" -
src/Helpers/Assert.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Helpers/Assert.hpp" … … 45 47 46 48 using namespace Assert; 49 50 #ifndef NDEBUG 47 51 48 52 Action _my_assert::defaultAction = Ask; … … 122 126 return ActionNames[defaultAction]; 123 127 } 128 129 #endif 130 -
src/Helpers/MemDebug.cpp
r980dd6 re6317b 10 10 #include <cstring> 11 11 #include <boost/thread.hpp> 12 13 #ifdef __GNUC__ 14 #include <execinfo.h> 15 #include <cxxabi.h> 16 #endif 12 17 13 18 using namespace std; … … 34 39 char file[length+1]; 35 40 int line; 41 #ifdef __GNUC__ // function tracking only works with GCC 42 // function names can get looooong 43 enum {length2 = 256}; 44 char function[length2+1]; 45 #endif 36 46 size_t nbytes; 37 47 bool isUsed; … … 96 106 for(entry_t *pos=begin;pos;pos=pos->next){ 97 107 cout << "\nChunk of " << pos->info.nbytes << " bytes" << " still available" << endl; 108 #ifdef __GNUC__ 109 cout << "Chunk reserved at: " << pos->info.function 110 << " (" << pos->info.file << ":" << pos->info.line << ")" << endl; 111 #else 98 112 cout << "Chunk reserved at: " << pos->info.file << ":" << pos->info.line << endl; 113 #endif 99 114 } 100 115 } … … 130 145 deleteEntry(entry); 131 146 } 132 } 147 148 #ifdef __GNUC__ 149 // this function let's us find the caller's name 150 char* getCaller(){ 151 // stack looks like this: 152 // getCaller(); 153 // operator new(); 154 // function_we_are_looking_for(); <- 155 const size_t max_depth = 3; 156 void* stack_addrs[max_depth]; 157 size_t stack_depth; 158 char **stack_strings=0; 159 const char *func_name=0; 160 const char *toplevel = "Global scope"; 161 char *retval=0; 162 163 // get the backtrace, depth three 164 stack_depth = backtrace(stack_addrs,max_depth); 165 stack_strings = backtrace_symbols(stack_addrs, stack_depth); 166 // used later for demangling 167 // reserved here, so we can free it unconditionally 168 char *dm_function = static_cast<char*>(malloc(entry_t::info_t::length2)); 169 if(!dm_function){ 170 // malloc failed... we are out of luck 171 throw std::bad_alloc(); 172 } 173 174 // see if we found our function name 175 if(stack_depth==max_depth){ 176 // find the mangled function name 177 char *begin = stack_strings[max_depth-1]; 178 // function name starts with a ( 179 while(*begin && *begin!='(') ++begin; 180 char *end=begin; 181 while(*end && *end!='+') ++end; 182 183 // see if we found our function name 184 if(*begin && *end){ 185 *begin++ = 0; 186 *end = 0; 187 // use the C++ demangler 188 189 size_t sz = entry_t::info_t::length2; 190 int status; 191 char *func_ret = abi::__cxa_demangle(begin, dm_function, &sz, &status); 192 if(func_ret){ 193 // abi might have realloced... 194 dm_function = func_ret; 195 func_name = dm_function; 196 } 197 else{ 198 // demangling failed... get the function name without demangling 199 func_name = begin; 200 } 201 } 202 else{ 203 // function name not found... get the whole line 204 func_name = stack_strings[max_depth-1]; 205 } 206 207 } 208 else{ 209 func_name = toplevel; 210 } 211 212 // now we copy the desired function name 213 if((retval = static_cast<char*>(malloc(strlen(func_name)+1)))){ 214 // we know that the string will fit, so strcpy is safe here 215 strcpy(retval,func_name); 216 } 217 else{ 218 free(stack_strings); // malloc()ed by backtrace_symbols 219 free(dm_function); 220 // uh-uh ... seems we are out of luck for allocations now 221 throw std::bad_alloc(); 222 } 223 free(dm_function); 224 free(stack_strings); // malloc()ed by backtrace_symbols 225 return retval; 226 } 227 #endif 228 } 229 230 #ifdef __GNUC__ 231 232 void *operator new(size_t nbytes,const char* file, int line, const char* func) throw(std::bad_alloc) { 233 234 // we need to lock, so that no one changes the linked list while we are here 235 boost::mutex::scoped_lock guard(Memory::memorylock); 236 237 // to avoid allocations of 0 bytes if someone screws up 238 // allocation with 0 byte size are undefined behavior, so we are 239 // free to handle it this way 240 if(!nbytes) { 241 nbytes = 1; 242 } 243 244 // get the size of the entry, including alignment 245 static const size_t entrySpace = Memory::doAlign(sizeof(Memory::entry_t)); 246 247 void *res; 248 if(!(res=malloc(entrySpace + nbytes))){ 249 // new must throw, when space is low 250 throw std::bad_alloc(); 251 } 252 253 // we got the space, so update the global info 254 Memory::state += nbytes; 255 if(Memory::state>Memory::max){ 256 Memory::max = Memory::state; 257 } 258 Memory::allocs++; 259 260 // build the entry in front of the space 261 Memory::entry_t *entry = (Memory::entry_t*) res; 262 memset(res,0,entrySpace); 263 entry->info.nbytes = nbytes; 264 entry->info.isUsed = true; 265 strncpy(entry->info.file,file,Memory::entry_t::info_t::length); 266 entry->info.file[Memory::entry_t::info_t::length] = '\0'; 267 entry->info.line=line; 268 strncpy(entry->info.function,func,Memory::entry_t::info_t::length2); 269 entry->info.function[Memory::entry_t::info_t::length2] = '\0'; 270 // the space starts behind the info 271 entry->info.location = (char*)res + entrySpace; 272 273 // add the entry at the end of the list 274 entry->next=0; // the created block is last in the list 275 entry->prev=Memory::end; // the created block is last in the list 276 if(!Memory::begin){ 277 // the list was empty... start a new one 278 Memory::begin=entry; 279 } 280 else { 281 // other blocks present... we can add to the last one 282 Memory::end->next=entry; 283 } 284 Memory::end=entry; 285 286 // get the checksum... 287 entry->checksum = Memory::calcChecksum(&entry->info); 288 // this will be set to true, when the block is removed from 289 // the list for any reason 290 entry->isIgnored = false; 291 292 // ok, space is prepared... the user can have it. 293 // the rest (constructor, deleting when something is thrown etc) 294 // is handled automatically 295 return entry->info.location; 296 } 297 298 #else 133 299 134 300 void *operator new(size_t nbytes,const char* file, int line) throw(std::bad_alloc) { … … 196 362 } 197 363 364 #endif 365 198 366 void *operator new(size_t nbytes) throw(std::bad_alloc) { 199 367 // Just forward to the other operator, when we do not know from 200 368 // where the allocation came 369 #ifdef __GNUC__ 370 // this might throw bad_alloc 371 char *caller = Memory::getCaller(); 372 void* retval = 0; 373 374 // if this throws, we have to clean up the caller anyway 375 try{ 376 retval = operator new(nbytes,"Unknown",0,caller); 377 } 378 catch(...) 379 { 380 free(caller); // malloc()ed by Memory::getCaller(); 381 throw; 382 } 383 free(caller); // malloc()ed by Memory::getCaller(); 384 return retval; 385 #else 201 386 return operator new(nbytes,"Unknown",0); 202 } 387 #endif 388 } 389 390 #ifdef __GNUC__ 391 392 void *operator new[] (size_t nbytes,const char* file, int line, const char* func) throw(std::bad_alloc) { 393 // The difference between new and new[] is just for compiler bookkeeping. 394 return operator new(nbytes,file,line,func); 395 } 396 397 #else 203 398 204 399 void *operator new[] (size_t nbytes,const char* file, int line) throw(std::bad_alloc) { … … 207 402 } 208 403 404 #endif 405 209 406 void *operator new[] (size_t nbytes) throw(std::bad_alloc) { 210 407 // Forward again 408 #ifdef __GNUC__ 409 // this might throw bad_alloc 410 char *caller = Memory::getCaller(); 411 void *retval=0; 412 413 // if this throws, we have to clean up the caller anyway 414 try{ 415 retval = operator new[] (nbytes,"Unknown",0,caller); 416 } 417 catch(...) 418 { 419 free(caller); // malloc()ed by Memory::getCaller(); 420 throw; 421 } 422 free(caller); // malloc()ed by Memory::getCaller(); 423 return retval; 424 #else 211 425 return operator new[] (nbytes,"Unknown",0); 426 #endif 212 427 } 213 428 -
src/Helpers/MemDebug.hpp
r980dd6 re6317b 28 28 #endif 29 29 30 #include <new> 31 32 // some light header files, that do weird new stuff and therefore need 33 // to be loaded before the define 34 #include <string> 35 #include <boost/optional.hpp> 36 #include <boost/shared_ptr.hpp> 37 #include <boost/function.hpp> 38 #include <boost/program_options.hpp> 39 40 30 41 namespace Memory { 31 42 … … 50 61 } 51 62 } 52 63 #ifdef __GNUC__ 64 void *operator new (size_t nbytes,const char* file, int line, const char* func) throw(std::bad_alloc); 65 void *operator new[] (size_t nbytes,const char* file, int line, const char* func) throw(std::bad_alloc); 66 #else 53 67 void *operator new (size_t nbytes,const char* file, int line) throw(std::bad_alloc); 54 68 void *operator new[] (size_t nbytes,const char* file, int line) throw(std::bad_alloc); 69 #endif 55 70 void operator delete (void *ptr,const char*, int) throw(); 56 71 void operator delete[] (void *ptr,const char*, int) throw(); 72 73 57 74 58 75 /** … … 60 77 * version that allows tracking. 61 78 */ 79 #ifdef __GNUC__ 80 #define new new(__FILE__,__LINE__,__PRETTY_FUNCTION__) 81 #else 62 82 #define new new(__FILE__,__LINE__) 83 #endif 63 84 64 85 #endif 65 86 #endif 66 87 88 89 #ifdef NDEBUG 90 #undef MEMDEBUG 91 #endif 67 92 68 93 #ifndef MEMDEBUG -
src/Legacy/oldmenu.cpp
r980dd6 re6317b 6 6 * 7 7 */ 8 9 #include "Helpers/MemDebug.hpp" 8 10 9 11 #include "Legacy/oldmenu.hpp" … … 26 28 #include "vector_ops.hpp" 27 29 #include "Plane.hpp" 30 #include "Line.hpp" 28 31 29 32 #include "UIElements/UIFactory.hpp" … … 191 194 // rotate vector around first angle 192 195 first->x = x; 193 first->x = RotateVector(first->x,z,b - M_PI);196 first->x = Line(zeroVec,z).rotateVector(first->x,b - M_PI); 194 197 Log() << Verbose(0) << "Rotated vector: " << first->x << endl, 195 198 // remove the projection onto the rotation plane of the second angle … … 207 210 // rotate another vector around second angle 208 211 n = y; 209 n = RotateVector(n,x,c - M_PI);212 n = Line(zeroVec,x).rotateVector(n,c - M_PI); 210 213 Log() << Verbose(0) << "2nd Rotated vector: " << n << endl; 211 214 -
src/Line.cpp
r980dd6 re6317b 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 9 8 10 #include "Line.hpp" 9 11 … … 11 13 12 14 #include "vector.hpp" 13 14 Line::Line(Vector &_origin, Vector &_direction) : 15 origin(new Vector(_origin)), 15 #include "log.hpp" 16 #include "verbose.hpp" 17 #include "gslmatrix.hpp" 18 #include "info.hpp" 19 #include "Exceptions/LinearDependenceException.hpp" 20 #include "Exceptions/SkewException.hpp" 21 #include "Plane.hpp" 22 23 using namespace std; 24 25 Line::Line(const Vector &_origin, const Vector &_direction) : 16 26 direction(new Vector(_direction)) 17 27 { 18 28 direction->Normalize(); 19 } 29 origin.reset(new Vector(_origin.partition(*direction).second)); 30 } 31 32 Line::Line(const Line &src) : 33 origin(new Vector(*src.origin)), 34 direction(new Vector(*src.direction)) 35 {} 20 36 21 37 Line::~Line() … … 24 40 25 41 double Line::distance(const Vector &point) const{ 26 return fabs(point.ScalarProduct(*direction) - origin->ScalarProduct(*direction)); 42 // get any vector from line to point 43 Vector helper = point - *origin; 44 // partition this vector along direction 45 // the residue points from the line to the point 46 return helper.partition(*direction).second.Norm(); 27 47 } 28 48 29 49 Vector Line::getClosestPoint(const Vector &point) const{ 30 double factor = point.ScalarProduct(*direction) - origin->ScalarProduct(*direction); 31 return (point - (factor * (*direction))); 32 } 50 // get any vector from line to point 51 Vector helper = point - *origin; 52 // partition this vector along direction 53 // add only the part along the direction 54 return *origin + helper.partition(*direction).first; 55 } 56 57 Vector Line::getDirection() const{ 58 return *direction; 59 } 60 61 Vector Line::getOrigin() const{ 62 return *origin; 63 } 64 65 vector<Vector> Line::getPointsOnLine() const{ 66 vector<Vector> res; 67 res.reserve(2); 68 res.push_back(*origin); 69 res.push_back(*origin+*direction); 70 return res; 71 } 72 73 /** Calculates the intersection of the two lines that are both on the same plane. 74 * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html 75 * \param *out output stream for debugging 76 * \param *Line1a first vector of first line 77 * \param *Line1b second vector of first line 78 * \param *Line2a first vector of second line 79 * \param *Line2b second vector of second line 80 * \return true - \a this will contain the intersection on return, false - lines are parallel 81 */ 82 Vector Line::getIntersection(const Line& otherLine) const{ 83 Info FunctionInfo(__func__); 84 85 pointset line1Points = getPointsOnLine(); 86 87 Vector Line1a = line1Points[0]; 88 Vector Line1b = line1Points[1]; 89 90 pointset line2Points = otherLine.getPointsOnLine(); 91 92 Vector Line2a = line2Points[0]; 93 Vector Line2b = line2Points[1]; 94 95 Vector res; 96 97 auto_ptr<GSLMatrix> M = auto_ptr<GSLMatrix>(new GSLMatrix(4,4)); 98 99 M->SetAll(1.); 100 for (int i=0;i<3;i++) { 101 M->Set(0, i, Line1a[i]); 102 M->Set(1, i, Line1b[i]); 103 M->Set(2, i, Line2a[i]); 104 M->Set(3, i, Line2b[i]); 105 } 106 107 //Log() << Verbose(1) << "Coefficent matrix is:" << endl; 108 //for (int i=0;i<4;i++) { 109 // for (int j=0;j<4;j++) 110 // cout << "\t" << M->Get(i,j); 111 // cout << endl; 112 //} 113 if (fabs(M->Determinant()) > MYEPSILON) { 114 Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl; 115 throw SkewException(__FILE__,__LINE__); 116 } 117 118 Log() << Verbose(1) << "INFO: Line1a = " << Line1a << ", Line1b = " << Line1b << ", Line2a = " << Line2a << ", Line2b = " << Line2b << "." << endl; 119 120 121 // constuct a,b,c 122 Vector a = Line1b - Line1a; 123 Vector b = Line2b - Line2a; 124 Vector c = Line2a - Line1a; 125 Vector d = Line2b - Line1b; 126 Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl; 127 if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) { 128 res.Zero(); 129 Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl; 130 throw LinearDependenceException(__FILE__,__LINE__); 131 } 132 133 // check for parallelity 134 Vector parallel; 135 double factor = 0.; 136 if (fabs(a.ScalarProduct(b)*a.ScalarProduct(b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) { 137 parallel = Line1a - Line2a; 138 factor = parallel.ScalarProduct(a)/a.Norm(); 139 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 140 res = Line2a; 141 Log() << Verbose(1) << "Lines conincide." << endl; 142 return res; 143 } else { 144 parallel = Line1a - Line2b; 145 factor = parallel.ScalarProduct(a)/a.Norm(); 146 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 147 res = Line2b; 148 Log() << Verbose(1) << "Lines conincide." << endl; 149 return res; 150 } 151 } 152 Log() << Verbose(1) << "Lines are parallel." << endl; 153 res.Zero(); 154 throw LinearDependenceException(__FILE__,__LINE__); 155 } 156 157 // obtain s 158 double s; 159 Vector temp1, temp2; 160 temp1 = c; 161 temp1.VectorProduct(b); 162 temp2 = a; 163 temp2.VectorProduct(b); 164 Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl; 165 if (fabs(temp2.NormSquared()) > MYEPSILON) 166 s = temp1.ScalarProduct(temp2)/temp2.NormSquared(); 167 else 168 s = 0.; 169 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl; 170 171 // construct intersection 172 res = a; 173 res.Scale(s); 174 res += Line1a; 175 Log() << Verbose(1) << "Intersection is at " << res << "." << endl; 176 177 return res; 178 } 179 180 /** Rotates the vector by an angle of \a alpha around this line. 181 * \param rhs Vector to rotate 182 * \param alpha rotation angle in radian 183 */ 184 Vector Line::rotateVector(const Vector &rhs, double alpha) const{ 185 Vector helper = rhs; 186 187 // translate the coordinate system so that the line goes through (0,0,0) 188 helper -= *origin; 189 190 // partition the vector into a part that gets rotated and a part that lies along the line 191 pair<Vector,Vector> parts = helper.partition(*direction); 192 193 // we just keep anything that is along the axis 194 Vector res = parts.first; 195 196 // the rest has to be rotated 197 Vector a = parts.second; 198 // we only have to do the rest, if we actually could partition the vector 199 if(!a.IsZero()){ 200 // construct a vector that is orthogonal to a and direction and has length |a| 201 Vector y = a; 202 // direction is normalized, so the result has length |a| 203 y.VectorProduct(*direction); 204 205 res += cos(alpha) * a + sin(alpha) * y; 206 } 207 208 // translate the coordinate system back 209 res += *origin; 210 return res; 211 } 212 213 Plane Line::getOrthogonalPlane(const Vector &origin) const{ 214 return Plane(getDirection(),origin); 215 } 216 217 Line makeLineThrough(const Vector &x1, const Vector &x2){ 218 if(x1==x2){ 219 throw LinearDependenceException(__FILE__,__LINE__); 220 } 221 return Line(x1,x1-x2); 222 } -
src/Line.hpp
r980dd6 re6317b 12 12 13 13 #include <memory> 14 #include <vector> 14 15 15 16 class Vector; 17 class Plane; 16 18 17 19 class Line : public Space 18 20 { 19 21 public: 20 Line(Vector &_origin, Vector &_direction); 22 Line(const Vector &_origin, const Vector &_direction); 23 Line(const Line& _src); 21 24 virtual ~Line(); 22 25 23 virtual double distance(const Vector &point) const=0; 24 virtual Vector getClosestPoint(const Vector &point) const=0; 26 virtual double distance(const Vector &point) const; 27 virtual Vector getClosestPoint(const Vector &point) const; 28 29 Vector getDirection() const; 30 Vector getOrigin() const; 31 32 std::vector<Vector> getPointsOnLine() const; 33 34 Vector getIntersection(const Line& otherLine) const; 35 36 Vector rotateVector(const Vector &rhs, double alpha) const; 37 38 Plane getOrthogonalPlane(const Vector &origin) const; 25 39 26 40 private: … … 29 43 }; 30 44 45 /** 46 * Named constructor to make a line through two points 47 */ 48 Line makeLineThrough(const Vector &x1, const Vector &x2); 49 31 50 #endif /* LINE_HPP_ */ -
src/Makefile.am
r980dd6 re6317b 113 113 Descriptors/AtomTypeDescriptor.cpp \ 114 114 Descriptors/MoleculeDescriptor.cpp \ 115 Descriptors/MoleculeIdDescriptor.cpp \ 116 Descriptors/MoleculeNameDescriptor.cpp \ 115 Descriptors/MoleculeIdDescriptor.cpp \ 116 Descriptors/MoleculeNameDescriptor.cpp \ 117 117 Descriptors/MoleculePtrDescriptor.cpp 118 118 … … 127 127 128 128 EXCEPTIONSOURCE = Exceptions/CustomException.cpp \ 129 Exceptions/LinearDependenceException.cpp \ 130 Exceptions/MathException.cpp \ 131 Exceptions/ZeroVectorException.cpp 129 Exceptions/LinearDependenceException.cpp \ 130 Exceptions/MathException.cpp \ 131 Exceptions/SkewException.cpp \ 132 Exceptions/ZeroVectorException.cpp 132 133 133 134 EXCEPTIONHEADER = Exceptions/CustomException.hpp \ 134 Exceptions/LinearDependenceException.hpp \ 135 Exceptions/MathException.hpp \ 136 Exceptions/ZeroVectorException.hpp 135 Exceptions/LinearDependenceException.hpp \ 136 Exceptions/MathException.hpp \ 137 Exceptions/SkewException.hpp \ 138 Exceptions/ZeroVectorException.hpp 137 139 138 140 SOURCE = \ -
src/Parser/ChangeTracker.cpp
r980dd6 re6317b 5 5 * Author: metzler 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "ChangeTracker.hpp" … … 13 15 * Constructor. Signs on as an observer for the World. 14 16 */ 15 ChangeTracker::ChangeTracker() { 17 ChangeTracker::ChangeTracker() : 18 Observable("ChangeTracker") 19 { 16 20 isConsistent = true; 17 21 World::getInstance().signOn(this); -
src/Parser/FormatParser.cpp
r980dd6 re6317b 5 5 * Author: metzler 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "FormatParser.hpp" … … 14 16 * Constructor. 15 17 */ 16 FormatParser::FormatParser() { 18 FormatParser::FormatParser() : 19 Observer("FormatParser") 20 { 17 21 ChangeTracker::get()->signOn(this); 18 22 saveStream = NULL; -
src/Parser/TremoloParser.cpp
r980dd6 re6317b 5 5 * Author: metzler 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Helpers/Assert.hpp" -
src/Parser/XyzParser.cpp
r980dd6 re6317b 5 5 * Author: metzler 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "XyzParser.hpp" -
src/Patterns/Cacheable.hpp
r980dd6 re6317b 35 35 return busy; 36 36 } 37 virtual std::string getName()=0; 37 38 protected: 38 39 bool busy; … … 64 65 // nothing to do when entering this 65 66 } 67 68 virtual std::string getName(){ 69 return "invalid"; 70 } 66 71 }; 67 72 … … 90 95 State::busy = false; 91 96 } 97 98 virtual std::string getName(){ 99 return "valid"; 100 } 92 101 private: 93 102 T content; … … 118 127 // nothing to do when entering this state 119 128 } 129 130 virtual std::string getName(){ 131 return "destroyed"; 132 } 120 133 }; 121 134 … … 124 137 125 138 public: 126 Cacheable(Observable *_owner, boost::function<T()> _recalcMethod );139 Cacheable(Observable *_owner, boost::function<T()> _recalcMethod, std::string name); 127 140 virtual ~Cacheable(); 128 141 … … 151 164 152 165 template<typename T> 153 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) : 166 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod, std::string name) : 167 Observer(name + "(Cached)"), 154 168 owner(_owner), 155 169 recalcMethod(_recalcMethod) … … 206 220 void Cacheable<T>::switchState(state_ptr newState){ 207 221 ASSERT(!state->isBusy(),"LOOP DETECTED: Cacheable state switched while recalculating.\nDid the recalculation trigger the Observable?"); 222 #ifdef LOG_OBSERVER 223 observerLog().addMessage() << "## Cacheable " << observerLog().getName(this) << " changed state (" << state->getName() 224 << "->" << newState->getName() << ")" << std::endl; 225 #endif 208 226 state = newState; 209 227 state->enter(); … … 215 233 { 216 234 public: 217 Cacheable(Observable *_owner, boost::function<T()> _recalcMethod );235 Cacheable(Observable *_owner, boost::function<T()> _recalcMethod,std::string name); 218 236 virtual ~Cacheable(); 219 237 220 238 const bool isValid() const; 221 const T &operator*() const;239 const T operator*() const; 222 240 223 241 // methods implemented for base-class Observer … … 230 248 231 249 template<typename T> 232 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) : 250 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod, std::string name) : 251 Observer(name), 233 252 recalcMethod(_recalcMethod) 234 253 {} 235 254 236 255 template<typename T> 237 const T &Cacheable<T>::operator*() const{256 const T Cacheable<T>::operator*() const{ 238 257 return recalcMethod(); 239 258 } -
src/Patterns/Observer.cpp
r980dd6 re6317b 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 9 8 10 #include "Observer.hpp" 9 11 … … 12 14 13 15 #include "Helpers/Assert.hpp" 16 #include "Helpers/MemDebug.hpp" 14 17 15 18 using namespace std; … … 43 46 // if no entry for this observable is found, an new one is created 44 47 // by the STL and initialized to 0 (see STL documentation) 48 #ifdef LOG_OBSERVER 49 observerLog().addMessage(depth[publisher]) << ">> Locking " << observerLog().getName(publisher) << endl; 50 #endif 45 51 depth[publisher]++; 46 52 } … … 60 66 // if zero is reached all observed blocks are done and we can 61 67 // start to notify our observers 62 if(--(depth[publisher])){} 68 --depth[publisher]; 69 #ifdef LOG_OBSERVER 70 observerLog().addMessage(depth[publisher]) << "<< Unlocking " << observerLog().getName(publisher) << endl; 71 #endif 72 if(depth[publisher]){} 63 73 else{ 64 74 publisher->notifyAll(); … … 123 133 callees_t::iterator iter; 124 134 for(iter=callees.begin();iter!=callees.end();++iter){ 135 #ifdef LOG_OBSERVER 136 observerLog().addMessage() << "-> Sending update from " << observerLog().getName(this) 137 << " to " << observerLog().getName((*iter).second) 138 << " (priority=" << (*iter).first << ")"<< endl; 139 #endif 125 140 (*iter).second->update(this); 126 141 } … … 165 180 // we do not need to publish all the changes at each time we are called 166 181 if(depth.find(this)==depth.end()) { 182 #ifdef LOG_OBSERVER 183 observerLog().addMessage() << "-* Update from " << observerLog().getName(publisher) 184 << " propagated by " << observerLog().getName(this) << endl; 185 #endif 167 186 notifyAll(); 187 } 188 else{ 189 #ifdef LOG_OBSERVER 190 observerLog().addMessage() << "-| Update from " << observerLog().getName(publisher) 191 << " not propagated by " << observerLog().getName(this) << endl; 192 #endif 168 193 } 169 194 } … … 177 202 void Observable::signOn(Observer *target,int priority) { 178 203 ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer"); 204 #ifdef LOG_OBSERVER 205 observerLog().addMessage() << "@@ Signing on " << observerLog().getName(target) << " to " << observerLog().getName(this) << endl; 206 #endif 179 207 bool res = false; 180 208 callees_t &callees = callTable[this]; … … 194 222 void Observable::signOff(Observer *target) { 195 223 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 224 #ifdef LOG_OBSERVER 225 observerLog().addMessage() << "** Signing off " << observerLog().getName(target) << " from " << observerLog().getName(this) << endl; 226 #endif 196 227 callees_t &callees = callTable[this]; 197 228 … … 238 269 /** Constructor for class Observable. 239 270 */ 240 Observable::Observable() 241 {} 271 Observable::Observable(string name) : 272 Observer(Observer::BaseConstructor()) 273 { 274 #ifdef LOG_OBSERVER 275 observerLog().addName(this,name); 276 observerLog().addMessage() << "++ Creating Observable " << observerLog().getName(this) << endl; 277 #endif 278 } 242 279 243 280 /** Destructor for class Observable. … … 246 283 Observable::~Observable() 247 284 { 285 #ifdef LOG_OBSERVER 286 observerLog().addMessage() << "-- Destroying Observable " << observerLog().getName(this) << endl; 287 #endif 248 288 if(callTable.count(this)) { 249 289 // delete all entries for this observable … … 259 299 /** Constructor for class Observer. 260 300 */ 261 Observer::Observer() 262 {} 301 Observer::Observer(string name) 302 { 303 #ifdef LOG_OBSERVER 304 observerLog().addName(this,name); 305 observerLog().addMessage() << "++ Creating Observer " << observerLog().getName(this) << endl; 306 #endif 307 } 308 309 /** 310 * Base Constructor for class Observer 311 * 312 * only called from Observable Constructor 313 */ 314 Observer::Observer(Observer::BaseConstructor){ 315 #ifdef LOG_OBSERVER 316 observerLog().addObservable(this); 317 #endif 318 } 263 319 264 320 /** Destructor for class Observer. 265 321 */ 266 322 Observer::~Observer() 267 {} 323 { 324 #ifdef LOG_OBSERVER 325 if(!observerLog().isObservable(this)){ 326 observerLog().addMessage() << "-- Destroying Observer " << observerLog().getName(this) << endl; 327 } 328 #endif 329 } 268 330 269 331 /** … … 296 358 } 297 359 } 360 361 #ifdef LOG_OBSERVER 362 363 /************************* Methods to do logging of the Observer Mechanism *********/ 364 365 // The log needs to exist fairly early, so we make it construct on first use, 366 // and never destroy it 367 ObserverLog &observerLog(){ 368 // yes, this memory is never freed... we need it around for the whole programm, 369 // so no freeing is possible 370 static ObserverLog *theLog = Memory::ignore(new ObserverLog()); 371 return *theLog; 372 } 373 374 375 ObserverLog::ObserverLog() : 376 count (0) 377 {} 378 379 ObserverLog::~ObserverLog(){} 380 381 string ObserverLog::getLog(){return log.str();} 382 383 std::string ObserverLog::getName(void* obj){ 384 return names[obj]; 385 } 386 387 bool ObserverLog::isObservable(void* obj){ 388 return observables.count(obj); 389 } 390 391 void ObserverLog::addName(void* obj , string name){ 392 stringstream sstr; 393 sstr << name << "_" << count++; 394 names[obj] = sstr.str(); 395 } 396 397 void ObserverLog::addObservable(void* obj){ 398 observables.insert(obj); 399 } 400 401 void ObserverLog::deleteName(void* obj){ 402 names.erase(obj); 403 } 404 405 void ObserverLog::deleteObservable(void* obj){ 406 observables.erase(obj); 407 } 408 409 stringstream &ObserverLog::addMessage(int depth){ 410 for(int i=depth;i--;) 411 log << " "; 412 return log; 413 } 414 415 #endif -
src/Patterns/Observer.hpp
r980dd6 re6317b 11 11 #include <map> 12 12 #include <set> 13 #include <string> 14 #include <sstream> 13 15 14 16 /** … … 28 30 */ 29 31 32 // Deactivate any logging when we are not in debug mode 33 #ifdef NDEBUG 34 #undef LOG_OBSERVER 35 #endif 36 30 37 class Observable; 31 38 class Notification; … … 58 65 template<class> friend class ObservedIterator; 59 66 60 public: 61 Observer(); 67 // indicates the constructor called from Observables 68 struct BaseConstructor{}; 69 70 public: 71 Observer(BaseConstructor); 72 Observer(std::string); 62 73 virtual ~Observer(); 63 74 … … 91 102 class Observable : public Observer { 92 103 public: 93 Observable( );104 Observable(std::string _name); 94 105 virtual ~Observable(); 95 106 … … 192 203 }; 193 204 205 #ifdef LOG_OBSERVER 206 207 /** 208 * This class is used to log the working of the observer mechanism 209 * 210 * TODO: make this conditional dependent on compiler Flag. 211 */ 212 class ObserverLog{ 213 friend class Observable; 214 friend class Observer; 215 template <typename> friend class Cacheable; 216 public: 217 ObserverLog(); 218 ~ObserverLog(); 219 std::string getLog(); // get everything that has been logged 220 std::string getName(void*); // get the name of an actor 221 bool isObservable(void*); 222 private: 223 int count; // number to reference each actor in this framework 224 std::map<void*,std::string> names; // List of names assigned to actors 225 std::set<void*> observables; // List of pointers to Observables. Needed to distinguish Observers and Observables 226 void addName(void*, std::string); // Assign a name to an Actor 227 void addObservable(void*); 228 void deleteName(void*); // delete the name of an Actor 229 void deleteObservable(void*); 230 std::stringstream &addMessage(int depth=0); // Add a Message to the logging 231 std::stringstream log; // The internal log object 232 }; 233 234 ObserverLog &observerLog(); 235 236 #endif 237 194 238 // extra macro is necessary to work with __LINE__ 195 239 #define PASTE(a,b) PASTE_HELPER(a,b) -
src/Plane.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Plane.hpp" … … 14 16 #include "Helpers/Assert.hpp" 15 17 #include <cmath> 18 #include "Line.hpp" 19 #include "Exceptions/MultipleSolutionsException.hpp" 16 20 17 21 /** … … 42 46 /** 43 47 * Constructs a plane from two direction vectors and a offset. 44 * If no offset is given a plane through origin is assumed45 48 */ 46 49 Plane::Plane(const Vector &y1, const Vector &y2, double _offset) throw(ZeroVectorException,LinearDependenceException) : … … 113 116 } 114 117 115 Vector Plane::getOffsetVector() {118 Vector Plane::getOffsetVector() const { 116 119 return getOffset()*getNormal(); 117 120 } 118 121 119 vector<Vector> Plane::getPointsOnPlane() {122 vector<Vector> Plane::getPointsOnPlane() const{ 120 123 std::vector<Vector> res; 121 124 res.reserve(3); … … 147 150 * \return true - \a this contains intersection point on return, false - line is parallel to plane (even if in-plane) 148 151 */ 149 Vector Plane::GetIntersection(const Vector &Origin, const Vector &LineVector)152 Vector Plane::GetIntersection(const Line& line) const 150 153 { 151 154 Info FunctionInfo(__func__); 152 155 Vector res; 153 156 154 // find intersection of a line defined by Offset and Direction with a plane defined by triangle 155 Vector Direction = LineVector - Origin; 156 Direction.Normalize(); 157 Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl; 158 //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl; 159 double factor1 = Direction.ScalarProduct(*normalVector.get()); 160 if (fabs(factor1) < MYEPSILON) { // Uniqueness: line parallel to plane? 161 Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl; 162 throw LinearDependenceException(__FILE__,__LINE__); 163 } 164 165 double factor2 = Origin.ScalarProduct(*normalVector.get()); 166 if (fabs(factor2-offset) < MYEPSILON) { // Origin is in-plane 167 Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl; 168 res = Origin; 169 return res; 170 } 171 157 double factor1 = getNormal().ScalarProduct(line.getDirection()); 158 if(fabs(factor1)<MYEPSILON){ 159 // the plane is parallel... under all circumstances this is bad luck 160 // we no have either no or infinite solutions 161 if(isContained(line.getOrigin())){ 162 throw MultipleSolutionsException<Vector>(__FILE__,__LINE__,line.getOrigin()); 163 } 164 else{ 165 throw LinearDependenceException(__FILE__,__LINE__); 166 } 167 } 168 169 double factor2 = getNormal().ScalarProduct(line.getOrigin()); 172 170 double scaleFactor = (offset-factor2)/factor1; 173 171 174 //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 175 Direction.Scale(scaleFactor); 176 res = Origin + Direction; 177 Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl; 178 179 // test whether resulting vector really is on plane 180 ASSERT(fabs(res.ScalarProduct(*normalVector) - offset) < MYEPSILON, 181 "Calculated line-Plane intersection does not lie on plane."); 172 res = line.getOrigin() + scaleFactor * line.getDirection(); 173 174 // tests to make sure the resulting vector really is on plane and line 175 ASSERT(isContained(res),"Calculated line-Plane intersection does not lie on plane."); 176 ASSERT(line.isContained(res),"Calculated line-Plane intersection does not lie on line."); 182 177 return res; 183 178 }; 179 180 Vector Plane::mirrorVector(const Vector &rhs) const { 181 Vector helper = getVectorToPoint(rhs); 182 // substract twice the Vector to the plane 183 return rhs+2*helper; 184 } 185 186 Line Plane::getOrthogonalLine(const Vector &origin) const{ 187 return Line(origin,getNormal()); 188 } 184 189 185 190 /************ Methods inherited from Space ****************/ -
src/Plane.hpp
r980dd6 re6317b 17 17 18 18 class Vector; 19 class Line; 19 20 20 21 class Plane : public Space … … 42 43 * Same as getOffset()*getNormal(); 43 44 */ 44 Vector getOffsetVector() ;45 Vector getOffsetVector() const; 45 46 46 47 /** 47 48 * returns three seperate points on this plane 48 49 */ 49 std::vector<Vector> getPointsOnPlane() ;50 std::vector<Vector> getPointsOnPlane() const; 50 51 51 52 // some calculations 52 Vector GetIntersection(const Vector &Origin, const Vector &LineVector); 53 Vector GetIntersection(const Line &Line) const; 54 55 Vector mirrorVector(const Vector &rhs) const; 56 57 /** 58 * get a Line that is orthogonal to this plane, going through a chosen 59 * point. 60 * 61 * The point does not have to lie on the plane itself. 62 */ 63 Line getOrthogonalLine(const Vector &origin) const; 53 64 54 65 /****** Methods inherited from Space ***********/ -
src/Space.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Space.hpp" … … 19 21 } 20 22 23 Vector Space::getVectorToPoint(const Vector &origin) const{ 24 Vector support = getClosestPoint(origin); 25 return support-origin; 26 } 27 21 28 bool Space::isContained(const Vector &point) const{ 22 29 return (distance(point)) < MYEPSILON; -
src/Space.hpp
r980dd6 re6317b 17 17 virtual ~Space(); 18 18 19 /** 20 * Calculates the distance between a Space and a Vector. 21 */ 19 22 virtual double distance(const Vector &point) const=0; 23 24 /** 25 * get the closest point inside the space to another point 26 */ 20 27 virtual Vector getClosestPoint(const Vector &point) const=0; 28 29 /** 30 * get the shortest Vector from a point to a Space. 31 * 32 * The Vector always points from the given Vector to the point in space 33 * returned by Plane::getClosestPoint(). 34 */ 35 virtual Vector getVectorToPoint(const Vector &point) const; 36 37 /** 38 * Test wether a point is contained in the space. 39 * 40 * returns true, when the point lies inside and false 41 * otherwise. 42 */ 21 43 virtual bool isContained(const Vector &point) const; 44 45 /** 46 * Tests if this space contains the center of the coordinate system. 47 */ 22 48 virtual bool hasZero() const; 23 49 -
src/UIElements/CommandLineUI/CommandLineDialog.cpp
r980dd6 re6317b 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 8 9 9 10 #include <iostream> -
src/UIElements/CommandLineUI/CommandLineStatusIndicator.cpp
r980dd6 re6317b 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 8 9 9 10 #include "CommandLineUI/CommandLineStatusIndicator.hpp" … … 15 16 using namespace std; 16 17 17 CommandLineStatusIndicator::CommandLineStatusIndicator() 18 CommandLineStatusIndicator::CommandLineStatusIndicator() : 19 Observer("CommandLineStatusIndicator") 18 20 { 19 21 Process::AddObserver(this); -
src/UIElements/CommandLineUI/CommandLineUIFactory.cpp
r980dd6 re6317b 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 8 9 9 10 #include "CommandLineUI/CommandLineUIFactory.hpp" -
src/UIElements/CommandLineUI/CommandLineWindow.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <boost/bind.hpp> -
src/UIElements/Dialog.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <cassert> -
src/UIElements/MainWindow.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "MainWindow.hpp" -
src/UIElements/Menu/ActionMenuItem.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> -
src/UIElements/Menu/DisplayMenuItem.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <sstream> -
src/UIElements/Menu/Menu.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "Menu.hpp" -
src/UIElements/Menu/MenuItem.cpp
r980dd6 re6317b 6 6 */ 7 7 8 8 #include "Helpers/MemDebug.hpp" 9 9 10 10 #include "Menu/MenuItem.hpp" -
src/UIElements/Menu/SeperatorItem.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 9 7 10 #include <string> 8 11 #include <sstream> -
src/UIElements/Menu/SubMenuItem.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "SubMenuItem.hpp" -
src/UIElements/Menu/TextMenu.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <boost/bind.hpp> -
src/UIElements/TextUI/TextDialog.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> -
src/UIElements/TextUI/TextStatusIndicator.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "TextUI/TextStatusIndicator.hpp" … … 14 16 using namespace std; 15 17 16 TextStatusIndicator::TextStatusIndicator() 18 TextStatusIndicator::TextStatusIndicator() : 19 Observer("TextStatusIndicator") 17 20 { 18 21 Process::AddObserver(this); -
src/UIElements/TextUI/TextUIFactory.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "TextUI/TextUIFactory.hpp" -
src/UIElements/TextUI/TextWindow.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "TextUI/TextWindow.hpp" -
src/UIElements/UIFactory.cpp
r980dd6 re6317b 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 8 9 9 10 #include <cassert> -
src/UIElements/Views/MethodStringView.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "MethodStringView.hpp" -
src/UIElements/Views/StreamStringView.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <sstream> -
src/UIElements/Views/StringView.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "StringView.hpp" -
src/UIElements/Views/View.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "View.hpp" -
src/World.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "World.hpp" … … 276 278 277 279 World::World() : 280 Observable("World"), 278 281 periode(new periodentafel), 279 282 configuration(new config), -
src/analysis_bonds.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "analysis_bonds.hpp" -
src/analysis_correlation.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> -
src/analyzer.cpp
r980dd6 re6317b 7 7 8 8 //============================ INCLUDES =========================== 9 10 #include "Helpers/MemDebug.hpp" 9 11 10 12 #include <cstring> -
src/atom.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include "atom.hpp" … … 14 16 #include "vector.hpp" 15 17 #include "World.hpp" 18 #include "molecule.hpp" 16 19 17 20 /************************************* Functions for class atom *************************************/ … … 21 24 */ 22 25 atom::atom() : 23 previous(NULL), next(NULL), father(this), sort(&nr)26 father(this), sort(&nr), mol(0) 24 27 { 25 28 node = &x; // TesselPoint::x can only be referenced from here … … 29 32 */ 30 33 atom::atom(atom *pointer) : 31 ParticleInfo(pointer), 32 previous(NULL), next(NULL), father(pointer), sort(&nr) 34 ParticleInfo(pointer),father(pointer), sort(&nr) 33 35 { 34 36 type = pointer->type; // copy element of atom … … 37 39 FixedIon = pointer->FixedIon; 38 40 node = &x; 41 mol = 0; 39 42 }; 40 43 41 44 atom *atom::clone(){ 42 45 atom *res = new atom(this); 43 res->previous=0;44 res->next=0;45 46 res->father = this; 46 47 res->sort = &res->nr; … … 50 51 res->FixedIon = FixedIon; 51 52 res->node = &x; 53 res->mol = 0; 52 54 World::getInstance().registerAtom(res); 53 55 return res; … … 59 61 atom::~atom() 60 62 { 63 removeFromMolecule(); 64 for(BondList::iterator iter=ListOfBonds.begin(); iter!=ListOfBonds.end();){ 65 // deleting the bond will invalidate the iterator !!! 66 bond *bond =*(iter++); 67 delete(bond); 68 } 61 69 }; 62 70 … … 67 75 atom *atom::GetTrueFather() 68 76 { 69 atom *walker = this; 70 do { 71 if (walker == walker->father) // top most father is the one that points on itself 72 break; 73 walker = walker->father; 74 } while (walker != NULL); 75 return walker; 77 if(father == this){ // top most father is the one that points on itself 78 return this; 79 } 80 else if(!father) { 81 return 0; 82 } 83 else { 84 return father->GetTrueFather(); 85 } 76 86 }; 77 87 … … 309 319 } 310 320 321 void atom::setMolecule(molecule *_mol){ 322 // take this atom from the old molecule 323 removeFromMolecule(); 324 mol = _mol; 325 if(!mol->containsAtom(this)){ 326 mol->AddAtom(this); 327 } 328 } 329 330 void atom::removeFromMolecule(){ 331 if(mol){ 332 if(mol->containsAtom(this)){ 333 mol->erase(this); 334 } 335 mol=0; 336 } 337 } 338 339 311 340 atom* NewAtom(atomId_t _id){ 312 341 atom * res =new atom(); -
src/atom.hpp
r980dd6 re6317b 34 34 class Vector; 35 35 class World; 36 class molecule; 36 37 37 38 /********************************************** declarations *******************************/ … … 44 45 friend void DeleteAtom(atom*); 45 46 public: 46 atom *previous; //!< previous atom in molecule list47 atom *next; //!< next atom in molecule list48 47 atom *father; //!< In many-body bond order fragmentations points to originating atom 49 48 int *sort; //!< sort criteria … … 89 88 virtual void setId(atomId_t); 90 89 90 void setMolecule(molecule*); 91 void removeFromMolecule(); 92 91 93 protected: 94 92 95 /** 93 96 * Protected constructor to ensure construction of atoms through the world. … … 108 111 virtual ~atom(); 109 112 private: 113 molecule *mol; // !< the molecule this atom belongs to 110 114 World* world; 111 115 atomId_t id; -
src/atom_atominfo.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "periodentafel.hpp" -
src/atom_bondedparticle.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom.hpp" -
src/atom_bondedparticleinfo.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom_bondedparticleinfo.hpp" -
src/atom_graphnode.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom_graphnode.hpp" -
src/atom_graphnodeinfo.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom_graphnodeinfo.hpp" -
src/atom_particleinfo.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom_particleinfo.hpp" -
src/atom_trajectoryparticle.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom.hpp" -
src/atom_trajectoryparticleinfo.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom_trajectoryparticleinfo.hpp" -
src/bond.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include "atom.hpp" -
src/bondgraph.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> -
src/boundary.cpp
r980dd6 re6317b 3 3 * Implementations and super-function for envelopes 4 4 */ 5 6 #include "Helpers/MemDebug.hpp" 5 7 6 8 #include "World.hpp" -
src/builder.cpp
r980dd6 re6317b 47 47 */ 48 48 49 #include "Helpers/MemDebug.hpp" 49 50 50 51 #include <boost/bind.hpp> … … 84 85 #include "version.h" 85 86 #include "World.hpp" 86 #include "Helpers/MemDebug.hpp" 87 87 88 88 89 /********************************************* Subsubmenu routine ************************************/ … … 2190 2191 ActionRegistry::purgeInstance(); 2191 2192 ActionHistory::purgeInstance(); 2193 #ifdef LOG_OBSERVER 2194 cout << observerLog().getLog(); 2195 #endif 2192 2196 Memory::getState(); 2193 2197 } -
src/config.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include <stdio.h> -
src/datacreator.cpp
r980dd6 re6317b 6 6 7 7 //============================ INCLUDES =========================== 8 9 #include "Helpers/MemDebug.hpp" 8 10 9 11 #include "datacreator.hpp" -
src/element.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include <iomanip> -
src/elements_db.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 const char *elementsDB =\ -
src/ellipsoid.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <gsl/gsl_multimin.h> -
src/errorlogger.cpp
r980dd6 re6317b 5 5 * Author: metzler 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <fstream> -
src/graph.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 using namespace std; -
src/gslmatrix.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 using namespace std; -
src/gslvector.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <cassert> -
src/helpers.cpp
r980dd6 re6317b 4 4 */ 5 5 6 #include "Helpers/MemDebug.hpp" 6 7 7 8 #include "helpers.hpp" -
src/info.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "info.hpp" -
src/joiner.cpp
r980dd6 re6317b 7 7 8 8 //============================ INCLUDES =========================== 9 10 #include "Helpers/MemDebug.hpp" 9 11 10 12 #include <cstring> -
src/leastsquaremin.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> -
src/linearsystemofequations.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "defs.hpp" -
src/linkedcell.cpp
r980dd6 re6317b 5 5 */ 6 6 7 #include "Helpers/MemDebug.hpp" 7 8 8 9 #include "atom.hpp" -
src/log.cpp
r980dd6 re6317b 5 5 * Author: metzler 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "logger.hpp" -
src/logger.cpp
r980dd6 re6317b 5 5 * Author: metzler 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <fstream> -
src/memoryallocator.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 using namespace std; -
src/memoryusageobserver.cpp
r980dd6 re6317b 4 4 * This class represents a Singleton for observing memory usage. 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include <cstdlib> -
src/molecule.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include <cstring> … … 35 37 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 36 38 */ 37 molecule::molecule(const periodentafel * const teil) : elemente(teil),38 MDSteps(0),39 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),40 ActiveFlag(false), IndexNr(-1),41 formula(this,boost::bind(&molecule::calcFormula,this) ),42 AtomCount(this,boost::bind(&molecule::doCountAtoms,this) ), last_atom(0), InternalPointer(begin())39 molecule::molecule(const periodentafel * const teil) : 40 Observable("molecule"), 41 elemente(teil), MDSteps(0), BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), 42 NoCyclicBonds(0), BondDistance(0.), ActiveFlag(false), IndexNr(-1), 43 formula(this,boost::bind(&molecule::calcFormula,this),"formula"), 44 AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), last_atom(0), InternalPointer(begin()) 43 45 { 44 46 … … 143 145 molecule::const_iterator iter = loc; 144 146 iter--; 147 atom* atom = *loc; 145 148 atoms.erase( loc ); 149 atom->removeFromMolecule(); 146 150 return iter; 147 151 } 148 152 149 molecule::const_iterator molecule::erase( atom * &key )153 molecule::const_iterator molecule::erase( atom * key ) 150 154 { 151 155 cout << "trying to erase atom" << endl; 152 156 molecule::const_iterator iter = find(key); 153 157 if (iter != end()){ 154 // remove this position and step forward (post-increment)155 158 atoms.erase( iter++ ); 159 key->removeFromMolecule(); 156 160 } 157 161 return iter; 158 162 } 159 163 160 molecule::const_iterator molecule::find ( atom * &key ) const164 molecule::const_iterator molecule::find ( atom * key ) const 161 165 { 162 166 return atoms.find( key ); … … 167 171 pair<atomSet::iterator,bool> res = atoms.insert(key); 168 172 return pair<iterator,bool>(iterator(res.first,this),res.second); 173 } 174 175 bool molecule::containsAtom(atom* key){ 176 return atoms.count(key); 169 177 } 170 178 … … 192 200 } 193 201 insert(pointer); 202 pointer->setMolecule(this); 194 203 } 195 204 return true; … … 657 666 bond * molecule::AddBond(atom *atom1, atom *atom2, int degree) 658 667 { 668 OBSERVE; 659 669 bond *Binder = NULL; 660 670 -
src/molecule.hpp
r980dd6 re6317b 153 153 size_t size() const; 154 154 const_iterator erase( const_iterator loc ); 155 const_iterator erase( atom * &key );156 const_iterator find ( atom * &key ) const;155 const_iterator erase( atom * key ); 156 const_iterator find ( atom * key ) const; 157 157 pair<iterator,bool> insert ( atom * const key ); 158 bool containsAtom(atom* key); 158 159 159 160 -
src/molecule_dynamics.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "World.hpp" -
src/molecule_fragmentation.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <cstring> -
src/molecule_geometry.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom.hpp" … … 16 18 #include "molecule.hpp" 17 19 #include "World.hpp" 20 #include "Plane.hpp" 21 #include <boost/foreach.hpp> 22 18 23 19 24 /************************************* Functions for class molecule *********************************/ … … 256 261 void molecule::Mirror(const Vector *n) 257 262 { 258 ActOnAllVectors( &Vector::Mirror, *n ); 263 OBSERVE; 264 Plane p(*n,0); 265 BOOST_FOREACH( atom* iter, atoms ){ 266 (*iter->node) = p.mirrorVector(*iter->node); 267 } 259 268 }; 260 269 -
src/molecule_graph.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom.hpp" -
src/molecule_pointcloud.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "atom.hpp" -
src/moleculelist.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include <cstring> … … 29 31 */ 30 32 MoleculeListClass::MoleculeListClass(World *_world) : 33 Observable("MoleculeListClass"), 31 34 world(_world) 32 35 { -
src/parser.cpp
r980dd6 re6317b 6 6 7 7 // ======================================= INCLUDES ========================================== 8 9 #include "Helpers/MemDebug.hpp" 8 10 9 11 #include <cstring> -
src/periodentafel.cpp
r980dd6 re6317b 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 using namespace std; -
src/tesselation.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <fstream> … … 17 19 #include "triangleintersectionlist.hpp" 18 20 #include "vector.hpp" 21 #include "Line.hpp" 19 22 #include "vector_ops.hpp" 20 23 #include "verbose.hpp" … … 441 444 442 445 try { 443 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x); 444 } 445 catch (LinearDependenceException &excp) { 446 Log() << Verbose(1) << excp; 447 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 448 return false; 449 } 450 451 DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl); 452 DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl); 453 DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl); 454 455 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 456 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl); 457 return true; 458 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 459 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl); 460 return true; 461 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 462 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl); 463 return true; 464 } 465 // Calculate cross point between one baseline and the line from the third endpoint to intersection 466 int i = 0; 467 do { 468 try { 469 CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node), 470 *(endpoints[(i+1)%3]->node->node), 471 *(endpoints[(i+2)%3]->node->node), 472 *Intersection); 446 Line centerLine = makeLineThrough(*MolCenter, *x); 447 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(centerLine); 448 449 DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl); 450 DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl); 451 DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl); 452 453 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 454 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl); 455 return true; 456 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 457 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl); 458 return true; 459 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 460 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl); 461 return true; 462 } 463 // Calculate cross point between one baseline and the line from the third endpoint to intersection 464 int i = 0; 465 do { 466 Line line1 = makeLineThrough(*(endpoints[i%3]->node->node),*(endpoints[(i+1)%3]->node->node)); 467 Line line2 = makeLineThrough(*(endpoints[(i+2)%3]->node->node),*Intersection); 468 CrossPoint = line1.getIntersection(line2); 473 469 helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 474 470 CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector … … 477 473 if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) { 478 474 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl); 479 i=4; 480 break; 475 return false; 481 476 } 482 477 i++; 483 } catch (LinearDependenceException &excp){ 484 break; 485 } 486 } while (i < 3); 487 if (i == 3) { 478 } while (i < 3); 488 479 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl); 489 480 return true; 490 } else { 491 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl); 481 } 482 catch (MathException &excp) { 483 Log() << Verbose(1) << excp; 484 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 492 485 return false; 493 486 } … … 516 509 GetCenter(&Direction); 517 510 try { 518 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction); 519 } 520 catch (LinearDependenceException &excp) { 511 Line l = makeLineThrough(*x, Direction); 512 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(l); 513 } 514 catch (MathException &excp) { 521 515 (*ClosestPoint) = (*x); 522 516 } … … 541 535 Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 542 536 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 543 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 537 Line l = makeLineThrough(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 538 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(l); 544 539 CrossDirection[i] = CrossPoint[i] - InPlane; 545 540 CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector -
src/tesselationhelpers.cpp
r980dd6 re6317b 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <fstream> … … 14 16 #include "tesselationhelpers.hpp" 15 17 #include "vector.hpp" 18 #include "Line.hpp" 16 19 #include "vector_ops.hpp" 17 20 #include "verbose.hpp" … … 666 669 // calculate the intersection between this projected baseline and Base 667 670 Vector *Intersection = new Vector; 668 *Intersection = GetIntersectionOfTwoLinesOnPlane(*(Base->endpoints[0]->node->node),669 *(Base->endpoints[1]->node->node),670 NewOffset, NewDirection);671 Line line1 = makeLineThrough(*(Base->endpoints[0]->node->node),*(Base->endpoints[1]->node->node)); 672 Line line2 = makeLineThrough(NewOffset, NewDirection); 673 *Intersection = line1.getIntersection(line2); 671 674 Normal = (*Intersection) - (*Base->endpoints[0]->node->node); 672 675 DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(Baseline)/Baseline.NormSquared()) << "." << endl); -
src/triangleintersectionlist.cpp
r980dd6 re6317b 8 8 * Author: heber 9 9 */ 10 11 #include "Helpers/MemDebug.hpp" 10 12 11 13 #include "triangleintersectionlist.hpp" -
src/unittests/CacheableTest.cpp
r980dd6 re6317b 55 55 56 56 threeNumbers(int _x,int _y, int _z) : 57 Observable("threeNumbers"), 57 58 x(_x),y(_y),z(_z), 58 sum(this,boost::bind(&threeNumbers::calcSum,this) ),59 sum(this,boost::bind(&threeNumbers::calcSum,this),"sum"), 59 60 hasRecalced(false) 60 61 {} … … 81 82 CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum)); 82 83 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced); 84 numbers->hasRecalced=false; 85 CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum)); 86 #ifndef NO_CACHING 87 CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced); 88 #else 89 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced); 90 #endif 83 91 } -
src/unittests/Makefile.am
r980dd6 re6317b 26 26 InfoUnitTest \ 27 27 LinearSystemOfEquationsUnitTest \ 28 LineUnittest \ 28 29 LinkedCellUnitTest \ 29 30 ListOfBondsUnitTest \ … … 69 70 infounittest.cpp \ 70 71 linearsystemofequationsunittest.cpp \ 72 LineUnittest.cpp \ 71 73 LinkedCellUnitTest.cpp \ 72 74 listofbondsunittest.cpp \ … … 104 106 infounittest.hpp \ 105 107 linearsystemofequationsunittest.hpp \ 108 LineUnittest.hpp \ 106 109 LinkedCellUnitTest.hpp \ 107 110 listofbondsunittest.hpp \ … … 170 173 LinearSystemOfEquationsUnitTest_LDADD = ${ALLLIBS} 171 174 175 LineUnittest_SOURCES = UnitTestMain.cpp LineUnittest.cpp LineUnittest.hpp 176 LineUnittest_LDADD = ${ALLLIBS} 177 172 178 LinkedCellUnitTest_SOURCES = UnitTestMain.cpp LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp 173 179 LinkedCellUnitTest_LDADD = ${ALLLIBS} -
src/unittests/ObserverTest.cpp
r980dd6 re6317b 33 33 public: 34 34 UpdateCountObserver() : 35 Observer("UpdateCountObserver"), 35 36 updates(0) 36 37 {}; … … 45 46 class SimpleObservable : public Observable { 46 47 public: 48 SimpleObservable() : 49 Observable("SimpleObservable") 50 {} 51 47 52 void changeMethod() { 48 53 OBSERVE; … … 54 59 class CallObservable : public Observable { 55 60 public: 61 CallObservable() : 62 Observable("CallObservable") 63 {} 64 56 65 void changeMethod1() { 57 66 OBSERVE; … … 70 79 class BlockObservable : public Observable { 71 80 public: 81 BlockObservable() : 82 Observable("BlockObservable") 83 {} 84 72 85 void changeMethod1(){ 73 86 OBSERVE; … … 104 117 class SuperObservable : public Observable { 105 118 public: 106 SuperObservable(){ 119 SuperObservable(): 120 Observable("SuperObservable") 121 { 107 122 subObservable = new SimpleObservable(); 108 123 subObservable->signOn(this); … … 123 138 public: 124 139 NotificationObservable() : 125 notification1(new Notification(this)), 126 notification2(new Notification(this)) 140 Observable("NotificationObservable"), 141 notification1(new Notification(this)), 142 notification2(new Notification(this)) 127 143 {} 128 144 … … 149 165 public: 150 166 NotificationObserver(Notification_ptr notification) : 167 Observer("NotificationObserver"), 151 168 requestedNotification(notification), 152 169 wasNotified(false) … … 172 189 173 190 ObservableCollection(int _num) : 174 num(_num) 191 Observable("ObservableCollection"), 192 num(_num) 175 193 { 176 194 for(int i=0; i<num; ++i){ -
src/unittests/PlaneUnittest.cpp
r980dd6 re6317b 17 17 18 18 #include "vector.hpp" 19 #include "Line.hpp" 19 20 20 21 CPPUNIT_TEST_SUITE_REGISTRATION( PlaneUnittest ); … … 153 154 CPPUNIT_ASSERT(fabs(p4->distance(e1)-1) < MYEPSILON); 154 155 CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(e1)); 155 156 157 } 156 } 157 158 void PlaneUnittest::mirrorTest(){ 159 Vector fixture; 160 161 // some Vectors that lie on the planes 162 fixture = p1->mirrorVector(e1); 163 CPPUNIT_ASSERT_EQUAL(fixture,e1); 164 fixture = p1->mirrorVector(e2); 165 CPPUNIT_ASSERT_EQUAL(fixture,e2); 166 fixture = p1->mirrorVector(e3); 167 CPPUNIT_ASSERT_EQUAL(fixture,e3); 168 169 fixture = p2->mirrorVector(zeroVec); 170 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec); 171 fixture = p2->mirrorVector(e1); 172 CPPUNIT_ASSERT_EQUAL(fixture,e1); 173 fixture = p2->mirrorVector(e2); 174 CPPUNIT_ASSERT_EQUAL(fixture,e2); 175 176 fixture = p3->mirrorVector(zeroVec); 177 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec); 178 fixture = p3->mirrorVector(e1); 179 CPPUNIT_ASSERT_EQUAL(fixture,e1); 180 fixture = p3->mirrorVector(e3); 181 CPPUNIT_ASSERT_EQUAL(fixture,e3); 182 183 fixture = p4->mirrorVector(zeroVec); 184 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec); 185 fixture = p4->mirrorVector(e2); 186 CPPUNIT_ASSERT_EQUAL(fixture,e2); 187 fixture = p4->mirrorVector(e3); 188 CPPUNIT_ASSERT_EQUAL(fixture,e3); 189 190 // some Vectors outside of the planes 191 { 192 Vector t = (2./3.)*(e1+e2+e3); 193 fixture = p1->mirrorVector(zeroVec); 194 CPPUNIT_ASSERT_EQUAL(fixture,t); 195 } 196 197 fixture = p2->mirrorVector(e3); 198 CPPUNIT_ASSERT_EQUAL(fixture,-1*e3); 199 fixture = p3->mirrorVector(e2); 200 CPPUNIT_ASSERT_EQUAL(fixture,-1*e2); 201 fixture = p4->mirrorVector(e1); 202 CPPUNIT_ASSERT_EQUAL(fixture,-1*e1); 203 } 204 205 void PlaneUnittest::LineIntersectionTest(){ 206 Vector fixture; 207 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 208 Line l1 = makeLineThrough(zeroVec,Vector(2,1,0)); 209 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e1, zeroVec).GetIntersection(l1) ); 210 CPPUNIT_ASSERT_EQUAL( zeroVec, fixture ); 211 212 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ??? 213 Line l2 = makeLineThrough(e1,Vector(0,1,1)); 214 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e2, Vector(2,1,0)).GetIntersection(l2) ); 215 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 216 } -
src/unittests/PlaneUnittest.hpp
r980dd6 re6317b 20 20 CPPUNIT_TEST ( pointsTest ); 21 21 CPPUNIT_TEST ( operationsTest ); 22 CPPUNIT_TEST ( mirrorTest ); 23 CPPUNIT_TEST ( LineIntersectionTest ); 22 24 CPPUNIT_TEST_SUITE_END(); 23 25 … … 30 32 void pointsTest(); 31 33 void operationsTest(); 34 void mirrorTest(); 35 void LineIntersectionTest(); 32 36 33 37 private: -
src/unittests/listofbondsunittest.cpp
r980dd6 re6317b 249 249 void ListOfBondsTest::DeleteAtomTest() 250 250 { 251 bond *Binder = NULL; 252 molecule::iterator iter = TestMolecule->begin(); 253 atom *atom1 = *iter; 254 iter++; 255 atom *atom2 = *iter; 256 CPPUNIT_ASSERT( atom1 != NULL ); 257 CPPUNIT_ASSERT( atom2 != NULL ); 258 259 // add bond 260 Binder = TestMolecule->AddBond(atom1, atom2, 1); 261 CPPUNIT_ASSERT( Binder != NULL ); 251 atom *atom1 = NULL; 252 atom *atom2 = NULL; 253 bond *Binder = NULL; 254 { 255 molecule::iterator iter = TestMolecule->begin(); 256 atom1 = *iter; 257 iter++; 258 atom2 = *iter; 259 } 260 CPPUNIT_ASSERT( atom1 != NULL ); 261 CPPUNIT_ASSERT( atom2 != NULL ); 262 263 // add bond 264 Binder = TestMolecule->AddBond(atom1, atom2, 1); 265 CPPUNIT_ASSERT( Binder != NULL ); 266 267 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom1->ListOfBonds.size() ); 268 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() ); 269 270 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() ); 262 271 263 272 // remove atom2 … … 268 277 269 278 // check if removed from molecule 270 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );271 }; 279 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() ); 280 }; -
src/unittests/manipulateAtomsTest.cpp
r980dd6 re6317b 55 55 public: 56 56 countObserver() : 57 Observer("countObserver"), 57 58 count(0) 58 59 {} -
src/unittests/vectorunittest.cpp
r980dd6 re6317b 215 215 } 216 216 217 /** UnitTest for line intersections.218 */219 void VectorTest::LineIntersectionTest()220 {221 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???222 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) );223 CPPUNIT_ASSERT_EQUAL( zero, fixture );224 225 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???226 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) );227 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );228 229 // four vectors equal to zero230 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException);231 //CPPUNIT_ASSERT_EQUAL( zero, fixture );232 233 // four vectors equal to unit234 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException);235 //CPPUNIT_ASSERT_EQUAL( zero, fixture );236 237 // two equal lines238 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two));239 CPPUNIT_ASSERT_EQUAL( unit, fixture );240 241 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???242 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) );243 CPPUNIT_ASSERT_EQUAL( unit, fixture );244 245 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???246 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) );247 CPPUNIT_ASSERT_EQUAL( zero, fixture );248 249 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???250 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) );251 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );252 };253 254 /** UnitTest for vector rotations.255 */256 void VectorTest::VectorRotationTest()257 {258 fixture = Vector(-1.,0.,0.);259 260 // zero vector does not change261 fixture = RotateVector(zero,unit, 1.);262 CPPUNIT_ASSERT_EQUAL( zero, fixture );263 264 fixture = RotateVector(zero, two, 1.);265 CPPUNIT_ASSERT_EQUAL( zero, fixture);266 267 // vector on axis does not change268 fixture = RotateVector(unit,unit, 1.);269 CPPUNIT_ASSERT_EQUAL( unit, fixture );270 271 // rotations272 fixture = RotateVector(otherunit, unit, M_PI);273 CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture );274 275 fixture = RotateVector(otherunit, unit, 2. * M_PI);276 CPPUNIT_ASSERT_EQUAL( otherunit, fixture );277 278 fixture = RotateVector(otherunit,unit, 0);279 CPPUNIT_ASSERT_EQUAL( otherunit, fixture );280 281 fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI);282 CPPUNIT_ASSERT_EQUAL( otherunit, fixture );283 }284 217 285 218 /** -
src/unittests/vectorunittest.hpp
r980dd6 re6317b 27 27 CPPUNIT_TEST ( ProjectionTest ); 28 28 CPPUNIT_TEST ( NormalsTest ); 29 CPPUNIT_TEST ( LineIntersectionTest );30 CPPUNIT_TEST ( VectorRotationTest );31 29 CPPUNIT_TEST ( IsInParallelepipedTest ); 32 30 CPPUNIT_TEST_SUITE_END(); -
src/vector.cpp
r980dd6 re6317b 5 5 */ 6 6 7 #include "Helpers/MemDebug.hpp" 7 8 8 9 #include "vector.hpp" … … 213 214 { 214 215 Vector tmp; 215 tmp[0] = x[1]* (y[2]) - x[2]* (y[1]);216 tmp[1] = x[2]* (y[0]) - x[0]* (y[2]);217 tmp[2] = x[0]* (y[1]) - x[1]* (y[0]);216 tmp[0] = x[1]* y[2] - x[2]* y[1]; 217 tmp[1] = x[2]* y[0] - x[0]* y[2]; 218 tmp[2] = x[0]* y[1] - x[1]* y[0]; 218 219 (*this) = tmp; 219 220 }; … … 232 233 *this -= tmp; 233 234 }; 234 235 /** Calculates the minimum distance vector of this vector to the plane.236 * \param *out output stream for debugging237 * \param *PlaneNormal normal of plane238 * \param *PlaneOffset offset of plane239 * \return distance to plane240 * \return distance vector onto to plane241 */242 Vector Vector::GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const243 {244 Vector temp = (*this) - PlaneOffset;245 temp.MakeNormalTo(PlaneNormal);246 temp.Scale(-1.);247 // then add connecting vector from plane to point248 temp += (*this)-PlaneOffset;249 double sign = temp.ScalarProduct(PlaneNormal);250 if (fabs(sign) > MYEPSILON)251 sign /= fabs(sign);252 else253 sign = 0.;254 255 temp.Normalize();256 temp.Scale(sign);257 return temp;258 };259 260 235 261 236 /** Calculates the minimum distance of this vector to the plane. … … 551 526 MatrixMultiplication(M); 552 527 }; 528 529 std::pair<Vector,Vector> Vector::partition(const Vector &rhs) const{ 530 double factor = ScalarProduct(rhs)/rhs.NormSquared(); 531 Vector res= factor * rhs; 532 return make_pair(res,(*this)-res); 533 } 534 535 std::pair<pointset,Vector> Vector::partition(const pointset &points) const{ 536 Vector helper = *this; 537 pointset res; 538 for(pointset::const_iterator iter=points.begin();iter!=points.end();++iter){ 539 pair<Vector,Vector> currPart = helper.partition(*iter); 540 res.push_back(currPart.first); 541 helper = currPart.second; 542 } 543 return make_pair(res,helper); 544 } 553 545 554 546 /** Do a matrix multiplication. … … 611 603 }; 612 604 613 /** Mirrors atom against a given plane.614 * \param n[] normal vector of mirror plane.615 */616 void Vector::Mirror(const Vector &n)617 {618 double projection;619 projection = ScalarProduct(n)/n.NormSquared(); // remove constancy from n (keep as logical one)620 // withdraw projected vector twice from original one621 for (int i=NDIM;i--;)622 at(i) -= 2.*projection*n[i];623 };624 625 605 /** Calculates orthonormal vector to one given vectors. 626 606 * Just subtracts the projection onto the given vector from this vector. … … 633 613 bool result = false; 634 614 double factor = y1.ScalarProduct(*this)/y1.NormSquared(); 635 Vector x1; 636 x1 = factor * y1; 615 Vector x1 = factor * y1; 637 616 SubtractVector(x1); 638 617 for (int i=NDIM;i--;) -
src/vector.hpp
r980dd6 re6317b 16 16 17 17 #include <memory> 18 #include <vector> 18 19 19 20 #include "defs.hpp" … … 21 22 22 23 /********************************************** declarations *******************************/ 24 25 class Vector; 26 27 typedef std::vector<Vector> pointset; 23 28 24 29 /** Single vector. … … 39 44 40 45 double DistanceSquared(const Vector &y) const; 41 Vector GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;42 46 double DistanceToSpace(const Space& space) const; 43 47 double PeriodicDistance(const Vector &y, const double * const cell_size) const; … … 56 60 void ProjectIt(const Vector &y); 57 61 Vector Projection(const Vector &y) const; 58 void Mirror(const Vector &x);59 62 void ScaleAll(const double *factor); 60 63 void Scale(const double factor); … … 66 69 bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 67 70 void WrapPeriodically(const double * const M, const double * const Minv); 71 std::pair<Vector,Vector> partition(const Vector&) const; 72 std::pair<pointset,Vector> partition(const pointset&) const; 68 73 69 74 // Accessors ussually come in pairs... and sometimes even more than that -
src/vector_ops.cpp
r980dd6 re6317b 5 5 * Author: crueger 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include "vector.hpp" … … 15 17 #include "Helpers/fast_functions.hpp" 16 18 #include "Exceptions/LinearDependenceException.hpp" 19 #include "Exceptions/SkewException.hpp" 17 20 18 21 #include <gsl/gsl_linalg.h> … … 110 113 return true; 111 114 }; 112 113 /** Rotates the vector relative to the origin around the axis given by \a *axis by an angle of \a alpha.114 * \param *axis rotation axis115 * \param alpha rotation angle in radian116 */117 Vector RotateVector(const Vector &vec,const Vector &axis, const double alpha)118 {119 Vector a,y;120 Vector res;121 // normalise this vector with respect to axis122 a = vec;123 a.ProjectOntoPlane(axis);124 // construct normal vector125 try {126 y = Plane(axis,a,0).getNormal();127 }128 catch (MathException &excp) {129 // The normal vector cannot be created if there is linar dependency.130 // Then the vector to rotate is on the axis and any rotation leads to the vector itself.131 return vec;132 }133 y.Scale(vec.Norm());134 // scale normal vector by sine and this vector by cosine135 y.Scale(sin(alpha));136 a.Scale(cos(alpha));137 res = vec.Projection(axis);138 // add scaled normal vector onto this vector139 res += y;140 // add part in axis direction141 res += a;142 return res;143 };144 145 /** Calculates the intersection of the two lines that are both on the same plane.146 * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html147 * \param *out output stream for debugging148 * \param *Line1a first vector of first line149 * \param *Line1b second vector of first line150 * \param *Line2a first vector of second line151 * \param *Line2b second vector of second line152 * \return true - \a this will contain the intersection on return, false - lines are parallel153 */154 Vector GetIntersectionOfTwoLinesOnPlane(const Vector &Line1a, const Vector &Line1b, const Vector &Line2a, const Vector &Line2b)155 {156 Info FunctionInfo(__func__);157 158 Vector res;159 160 auto_ptr<GSLMatrix> M = auto_ptr<GSLMatrix>(new GSLMatrix(4,4));161 162 M->SetAll(1.);163 for (int i=0;i<3;i++) {164 M->Set(0, i, Line1a[i]);165 M->Set(1, i, Line1b[i]);166 M->Set(2, i, Line2a[i]);167 M->Set(3, i, Line2b[i]);168 }169 170 //Log() << Verbose(1) << "Coefficent matrix is:" << endl;171 //for (int i=0;i<4;i++) {172 // for (int j=0;j<4;j++)173 // cout << "\t" << M->Get(i,j);174 // cout << endl;175 //}176 if (fabs(M->Determinant()) > MYEPSILON) {177 Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl;178 throw LinearDependenceException(__FILE__,__LINE__);179 }180 181 Log() << Verbose(1) << "INFO: Line1a = " << Line1a << ", Line1b = " << Line1b << ", Line2a = " << Line2a << ", Line2b = " << Line2b << "." << endl;182 183 184 // constuct a,b,c185 Vector a = Line1b - Line1a;186 Vector b = Line2b - Line2a;187 Vector c = Line2a - Line1a;188 Vector d = Line2b - Line1b;189 Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl;190 if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {191 res.Zero();192 Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl;193 throw LinearDependenceException(__FILE__,__LINE__);194 }195 196 // check for parallelity197 Vector parallel;198 double factor = 0.;199 if (fabs(a.ScalarProduct(b)*a.ScalarProduct(b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {200 parallel = Line1a - Line2a;201 factor = parallel.ScalarProduct(a)/a.Norm();202 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {203 res = Line2a;204 Log() << Verbose(1) << "Lines conincide." << endl;205 return res;206 } else {207 parallel = Line1a - Line2b;208 factor = parallel.ScalarProduct(a)/a.Norm();209 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {210 res = Line2b;211 Log() << Verbose(1) << "Lines conincide." << endl;212 return res;213 }214 }215 Log() << Verbose(1) << "Lines are parallel." << endl;216 res.Zero();217 throw LinearDependenceException(__FILE__,__LINE__);218 }219 220 // obtain s221 double s;222 Vector temp1, temp2;223 temp1 = c;224 temp1.VectorProduct(b);225 temp2 = a;226 temp2.VectorProduct(b);227 Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl;228 if (fabs(temp2.NormSquared()) > MYEPSILON)229 s = temp1.ScalarProduct(temp2)/temp2.NormSquared();230 else231 s = 0.;232 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;233 234 // construct intersection235 res = a;236 res.Scale(s);237 res += Line1a;238 Log() << Verbose(1) << "Intersection is at " << res << "." << endl;239 240 return res;241 }; -
src/vector_ops.hpp
r980dd6 re6317b 10 10 11 11 bool LSQdistance(Vector &res,const Vector **vectors, int num); 12 Vector RotateVector(const Vector &vec,const Vector &axis, const double alpha);13 Vector GetIntersectionOfTwoLinesOnPlane(const Vector &Line1a, const Vector &Line1b, const Vector &Line2a, const Vector &Line2b);14 12 15 13 #endif /* VECTOR_OPS_HPP_ */ -
src/verbose.cpp
r980dd6 re6317b 1 1 using namespace std; 2 3 #include "Helpers/MemDebug.hpp" 2 4 3 5 #include "info.hpp"
Note:
See TracChangeset
for help on using the changeset viewer.