Changes in / [980dd6:e6317b]


Ignore:
Location:
src
Files:
5 added
165 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <string>
     
    1517using namespace std;
    1618
     19Action::state_ptr getEmptyState() {
     20  return Action::state_ptr(Memory::ignore(new ActionState()));
     21}
     22
    1723// 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()));
     24Action::state_ptr Action::success = getEmptyState();
     25Action::state_ptr Action::failure = getEmptyState();
    2026
    2127Action::Action(std::string _name,bool _doRegister) :
  • src/Actions/ActionHistory.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "ActionHistory.hpp"
  • src/Actions/ActionRegistry.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/ActionRegistry.hpp"
  • src/Actions/ActionSequence.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/ActionSequence.hpp"
  • src/Actions/AnalysisAction/MolecularVolumeAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/AnalysisAction/MolecularVolumeAction.hpp"
  • src/Actions/AnalysisAction/PairCorrelationAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/AnalysisAction/PairCorrelationAction.hpp"
  • src/Actions/AnalysisAction/PrincipalAxisSystemAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
  • src/Actions/AtomAction/AddAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/AtomAction/AddAction.hpp"
  • src/Actions/AtomAction/ChangeElementAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/AtomAction/ChangeElementAction.hpp"
  • src/Actions/AtomAction/RemoveAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/AtomAction/RemoveAction.hpp"
  • src/Actions/CmdAction/BondLengthTableAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/CmdAction/BondLengthTableAction.hpp"
  • src/Actions/CmdAction/ElementDbAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/CmdAction/ElementDbAction.hpp"
  • src/Actions/CmdAction/FastParsingAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/CmdAction/FastParsingAction.hpp"
  • src/Actions/CmdAction/HelpAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/CmdAction/HelpAction.hpp"
  • src/Actions/CmdAction/VerboseAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/CmdAction/VerboseAction.hpp"
  • src/Actions/CmdAction/VersionAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/CmdAction/VersionAction.hpp"
  • src/Actions/ErrorAction.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
  • src/Actions/FragmentationAction/DepthFirstSearchAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
  • src/Actions/FragmentationAction/FragmentationAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/FragmentationAction/FragmentationAction.hpp"
  • src/Actions/FragmentationAction/SubgraphDissectionAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
  • src/Actions/MakroAction.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <string>
  • src/Actions/ManipulateAtomsProcess.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "ManipulateAtomsProcess.hpp"
  • src/Actions/MapOfActions.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810using namespace std;
  • src/Actions/MethodAction.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
  • src/Actions/MoleculeAction/BondFileAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/BondFileAction.hpp"
  • src/Actions/MoleculeAction/ChangeNameAction.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/ChangeNameAction.hpp"
  • src/Actions/MoleculeAction/FillWithMoleculeAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
  • src/Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
  • src/Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
  • src/Actions/MoleculeAction/SaveAdjacencyAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
  • src/Actions/MoleculeAction/SaveBondsAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/SaveBondsAction.hpp"
  • src/Actions/MoleculeAction/SaveTemperatureAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
  • src/Actions/MoleculeAction/SuspendInWaterAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/SuspendInWaterAction.hpp"
  • src/Actions/MoleculeAction/TranslateAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/TranslateAction.hpp"
  • src/Actions/MoleculeAction/VerletIntegrationAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/MoleculeAction/VerletIntegrationAction.hpp"
  • src/Actions/ParserAction/LoadXyzAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/ParserAction/LoadXyzAction.hpp"
  • src/Actions/ParserAction/SaveXyzAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/ParserAction/SaveXyzAction.hpp"
  • src/Actions/Process.cpp

    r980dd6 re6317b  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Process.hpp"
    911
     
    1113
    1214Process::Process(int _maxSteps, std::string _name, bool _doRegister) :
     15  Observable("Process"),
    1316  Action(_name,_doRegister),
    1417  maxSteps(_maxSteps),
  • src/Actions/TesselationAction/ConvexEnvelopeAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
  • src/Actions/TesselationAction/NonConvexEnvelopeAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
  • src/Actions/WorldAction/AddEmptyBoundaryAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/AddEmptyBoundaryAction.hpp"
  • src/Actions/WorldAction/BoundInBoxAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/BoundInBoxAction.hpp"
  • src/Actions/WorldAction/CenterInBoxAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/CenterInBoxAction.hpp"
  • src/Actions/WorldAction/CenterOnEdgeAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
  • src/Actions/WorldAction/ChangeBoxAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/ChangeBoxAction.hpp"
  • src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
  • src/Actions/WorldAction/RepeatBoxAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/RepeatBoxAction.hpp"
  • src/Actions/WorldAction/ScaleBoxAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/ScaleBoxAction.hpp"
  • src/Actions/WorldAction/SetDefaultNameAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/SetDefaultNameAction.hpp"
  • src/Actions/WorldAction/SetGaussianBasisAction.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Actions/WorldAction/SetGaussianBasisAction.hpp"
  • src/CommandLineParser.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <boost/program_options.hpp>
  • src/Descriptors/AtomDescriptor.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Descriptors/AtomDescriptor.hpp"
  • src/Descriptors/AtomIdDescriptor.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "AtomIdDescriptor.hpp"
  • src/Descriptors/AtomTypeDescriptor.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Descriptors/AtomTypeDescriptor.hpp"
  • src/Descriptors/MoleculeDescriptor.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Descriptors/MoleculeDescriptor.hpp"
  • src/Descriptors/MoleculeIdDescriptor.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "MoleculeIdDescriptor.hpp"
  • src/Descriptors/MoleculePtrDescriptor.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "MoleculePtrDescriptor.hpp"
  • src/Exceptions/CustomException.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "CustomException.hpp"
  • src/Exceptions/LinearDependenceException.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "LinearDependenceException.hpp"
  • src/Exceptions/MathException.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "MathException.hpp"
  • src/Exceptions/ZeroVectorException.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "ZeroVectorException.hpp"
  • src/Helpers/Assert.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Helpers/Assert.hpp"
     
    4547
    4648using namespace Assert;
     49
     50#ifndef NDEBUG
    4751
    4852Action _my_assert::defaultAction = Ask;
     
    122126  return ActionNames[defaultAction];
    123127}
     128
     129#endif
     130
  • src/Helpers/MemDebug.cpp

    r980dd6 re6317b  
    1010#include <cstring>
    1111#include <boost/thread.hpp>
     12
     13#ifdef __GNUC__
     14#include <execinfo.h>
     15#include <cxxabi.h>
     16#endif
    1217
    1318using namespace std;
     
    3439      char file[length+1];
    3540      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
    3646      size_t nbytes;
    3747      bool isUsed;
     
    96106    for(entry_t *pos=begin;pos;pos=pos->next){
    97107      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
    98112      cout << "Chunk reserved at: " << pos->info.file << ":" << pos->info.line << endl;
     113#endif
    99114    }
    100115  }
     
    130145    deleteEntry(entry);
    131146  }
    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
     232void *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
    133299
    134300void *operator new(size_t nbytes,const char* file, int line) throw(std::bad_alloc) {
     
    196362}
    197363
     364#endif
     365
    198366void *operator new(size_t nbytes) throw(std::bad_alloc) {
    199367  // Just forward to the other operator, when we do not know from
    200368  // 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
    201386  return operator new(nbytes,"Unknown",0);
    202 }
     387#endif
     388}
     389
     390#ifdef __GNUC__
     391
     392void *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
    203398
    204399void *operator new[] (size_t nbytes,const char* file, int line) throw(std::bad_alloc) {
     
    207402}
    208403
     404#endif
     405
    209406void *operator new[] (size_t nbytes) throw(std::bad_alloc) {
    210407  // 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
    211425  return operator new[] (nbytes,"Unknown",0);
     426#endif
    212427}
    213428
  • src/Helpers/MemDebug.hpp

    r980dd6 re6317b  
    2828#endif
    2929
     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
    3041namespace Memory {
    3142
     
    5061  }
    5162}
    52 
     63#ifdef __GNUC__
     64void *operator new   (size_t nbytes,const char* file, int line, const char* func) throw(std::bad_alloc);
     65void *operator new[] (size_t nbytes,const char* file, int line, const char* func) throw(std::bad_alloc);
     66#else
    5367void *operator new   (size_t nbytes,const char* file, int line) throw(std::bad_alloc);
    5468void *operator new[] (size_t nbytes,const char* file, int line) throw(std::bad_alloc);
     69#endif
    5570void operator delete   (void *ptr,const char*, int) throw();
    5671void operator delete[] (void *ptr,const char*, int) throw();
     72
     73
    5774
    5875/**
     
    6077 * version that allows tracking.
    6178 */
     79#ifdef __GNUC__
     80#define new new(__FILE__,__LINE__,__PRETTY_FUNCTION__)
     81#else
    6282#define new new(__FILE__,__LINE__)
     83#endif
    6384
    6485#endif
    6586#endif
    6687
     88
     89#ifdef NDEBUG
     90#undef MEMDEBUG
     91#endif
    6792
    6893#ifndef MEMDEBUG
  • src/Legacy/oldmenu.cpp

    r980dd6 re6317b  
    66 *
    77 */
     8
     9#include "Helpers/MemDebug.hpp"
    810
    911#include "Legacy/oldmenu.hpp"
     
    2628#include "vector_ops.hpp"
    2729#include "Plane.hpp"
     30#include "Line.hpp"
    2831
    2932#include "UIElements/UIFactory.hpp"
     
    191194          // rotate vector around first angle
    192195          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);
    194197          Log() << Verbose(0) << "Rotated vector: " << first->x << endl,
    195198          // remove the projection onto the rotation plane of the second angle
     
    207210          // rotate another vector around second angle
    208211          n = y;
    209           n = RotateVector(n,x,c - M_PI);
     212          n = Line(zeroVec,x).rotateVector(n,c - M_PI);
    210213          Log() << Verbose(0) << "2nd Rotated vector: " << n << endl;
    211214
  • src/Line.cpp

    r980dd6 re6317b  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Line.hpp"
    911
     
    1113
    1214#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
     23using namespace std;
     24
     25Line::Line(const Vector &_origin, const Vector &_direction) :
    1626  direction(new Vector(_direction))
    1727{
    1828  direction->Normalize();
    19 }
     29  origin.reset(new Vector(_origin.partition(*direction).second));
     30}
     31
     32Line::Line(const Line &src) :
     33  origin(new Vector(*src.origin)),
     34  direction(new Vector(*src.direction))
     35{}
    2036
    2137Line::~Line()
     
    2440
    2541double 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();
    2747}
    2848
    2949Vector 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
     57Vector Line::getDirection() const{
     58  return *direction;
     59}
     60
     61Vector Line::getOrigin() const{
     62  return *origin;
     63}
     64
     65vector<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 */
     82Vector 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 */
     184Vector 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
     213Plane Line::getOrthogonalPlane(const Vector &origin) const{
     214  return Plane(getDirection(),origin);
     215}
     216
     217Line 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  
    1212
    1313#include <memory>
     14#include <vector>
    1415
    1516class Vector;
     17class Plane;
    1618
    1719class Line : public Space
    1820{
    1921public:
    20   Line(Vector &_origin, Vector &_direction);
     22  Line(const Vector &_origin, const Vector &_direction);
     23  Line(const Line& _src);
    2124  virtual ~Line();
    2225
    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;
    2539
    2640private:
     
    2943};
    3044
     45/**
     46 * Named constructor to make a line through two points
     47 */
     48Line makeLineThrough(const Vector &x1, const Vector &x2);
     49
    3150#endif /* LINE_HPP_ */
  • src/Makefile.am

    r980dd6 re6317b  
    113113  Descriptors/AtomTypeDescriptor.cpp \
    114114  Descriptors/MoleculeDescriptor.cpp \
    115   Descriptors/MoleculeIdDescriptor.cpp \ 
    116   Descriptors/MoleculeNameDescriptor.cpp \ 
     115  Descriptors/MoleculeIdDescriptor.cpp \
     116  Descriptors/MoleculeNameDescriptor.cpp \
    117117  Descriptors/MoleculePtrDescriptor.cpp
    118118                                   
     
    127127                                   
    128128EXCEPTIONSOURCE = 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
    132133                                 
    133134EXCEPTIONHEADER = 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
    137139
    138140SOURCE = \
  • src/Parser/ChangeTracker.cpp

    r980dd6 re6317b  
    55 *      Author: metzler
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "ChangeTracker.hpp"
     
    1315 * Constructor. Signs on as an observer for the World.
    1416 */
    15 ChangeTracker::ChangeTracker() {
     17ChangeTracker::ChangeTracker() :
     18  Observable("ChangeTracker")
     19{
    1620  isConsistent = true;
    1721  World::getInstance().signOn(this);
  • src/Parser/FormatParser.cpp

    r980dd6 re6317b  
    55 *      Author: metzler
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "FormatParser.hpp"
     
    1416 * Constructor.
    1517 */
    16 FormatParser::FormatParser() {
     18FormatParser::FormatParser() :
     19  Observer("FormatParser")
     20{
    1721  ChangeTracker::get()->signOn(this);
    1822  saveStream = NULL;
  • src/Parser/TremoloParser.cpp

    r980dd6 re6317b  
    55 *      Author: metzler
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Helpers/Assert.hpp"
  • src/Parser/XyzParser.cpp

    r980dd6 re6317b  
    55 *      Author: metzler
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "XyzParser.hpp"
  • src/Patterns/Cacheable.hpp

    r980dd6 re6317b  
    3535        return busy;
    3636      }
     37    virtual std::string getName()=0;
    3738    protected:
    3839      bool busy;
     
    6465        // nothing to do when entering this
    6566      }
     67
     68      virtual std::string getName(){
     69        return "invalid";
     70      }
    6671    };
    6772
     
    9095        State::busy = false;
    9196      }
     97
     98      virtual std::string getName(){
     99        return "valid";
     100      }
    92101    private:
    93102      T content;
     
    118127        // nothing to do when entering this state
    119128      }
     129
     130      virtual std::string getName(){
     131        return "destroyed";
     132      }
    120133    };
    121134
     
    124137
    125138  public:
    126     Cacheable(Observable *_owner, boost::function<T()> _recalcMethod);
     139    Cacheable(Observable *_owner, boost::function<T()> _recalcMethod, std::string name);
    127140    virtual ~Cacheable();
    128141
     
    151164
    152165  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)"),
    154168    owner(_owner),
    155169    recalcMethod(_recalcMethod)
     
    206220  void Cacheable<T>::switchState(state_ptr newState){
    207221    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
    208226    state = newState;
    209227    state->enter();
     
    215233  {
    216234  public:
    217     Cacheable(Observable *_owner, boost::function<T()> _recalcMethod);
     235    Cacheable(Observable *_owner, boost::function<T()> _recalcMethod,std::string name);
    218236    virtual ~Cacheable();
    219237
    220238    const bool isValid() const;
    221     const T& operator*() const;
     239    const T operator*() const;
    222240
    223241    // methods implemented for base-class Observer
     
    230248
    231249  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),
    233252    recalcMethod(_recalcMethod)
    234253  {}
    235254
    236255  template<typename T>
    237   const T& Cacheable<T>::operator*() const{
     256  const T Cacheable<T>::operator*() const{
    238257    return recalcMethod();
    239258  }
  • src/Patterns/Observer.cpp

    r980dd6 re6317b  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Observer.hpp"
    911
     
    1214
    1315#include "Helpers/Assert.hpp"
     16#include "Helpers/MemDebug.hpp"
    1417
    1518using namespace std;
     
    4346  // if no entry for this observable is found, an new one is created
    4447  // 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
    4551  depth[publisher]++;
    4652}
     
    6066  // if zero is reached all observed blocks are done and we can
    6167  // 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]){}
    6373  else{
    6474    publisher->notifyAll();
     
    123133      callees_t::iterator iter;
    124134      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
    125140        (*iter).second->update(this);
    126141      }
     
    165180    // we do not need to publish all the changes at each time we are called
    166181    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
    167186      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
    168193    }
    169194  }
     
    177202void Observable::signOn(Observer *target,int priority) {
    178203  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
    179207  bool res = false;
    180208  callees_t &callees = callTable[this];
     
    194222void Observable::signOff(Observer *target) {
    195223  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
    196227  callees_t &callees = callTable[this];
    197228
     
    238269/** Constructor for class Observable.
    239270 */
    240 Observable::Observable()
    241 {}
     271Observable::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}
    242279
    243280/** Destructor for class Observable.
     
    246283Observable::~Observable()
    247284{
     285#ifdef LOG_OBSERVER
     286  observerLog().addMessage() << "-- Destroying Observable " << observerLog().getName(this) << endl;
     287#endif
    248288  if(callTable.count(this)) {
    249289    // delete all entries for this observable
     
    259299/** Constructor for class Observer.
    260300 */
    261 Observer::Observer()
    262 {}
     301Observer::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 */
     314Observer::Observer(Observer::BaseConstructor){
     315#ifdef LOG_OBSERVER
     316  observerLog().addObservable(this);
     317#endif
     318}
    263319
    264320/** Destructor for class Observer.
    265321 */
    266322Observer::~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}
    268330
    269331/**
     
    296358  }
    297359}
     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
     367ObserverLog &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
     375ObserverLog::ObserverLog() :
     376  count (0)
     377{}
     378
     379ObserverLog::~ObserverLog(){}
     380
     381string ObserverLog::getLog(){return log.str();}
     382
     383std::string ObserverLog::getName(void* obj){
     384  return names[obj];
     385}
     386
     387bool ObserverLog::isObservable(void* obj){
     388  return observables.count(obj);
     389}
     390
     391void ObserverLog::addName(void* obj , string name){
     392  stringstream sstr;
     393  sstr << name << "_" << count++;
     394  names[obj] = sstr.str();
     395}
     396
     397void ObserverLog::addObservable(void* obj){
     398  observables.insert(obj);
     399}
     400
     401void ObserverLog::deleteName(void* obj){
     402  names.erase(obj);
     403}
     404
     405void ObserverLog::deleteObservable(void* obj){
     406  observables.erase(obj);
     407}
     408
     409stringstream &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  
    1111#include <map>
    1212#include <set>
     13#include <string>
     14#include <sstream>
    1315
    1416/**
     
    2830 */
    2931
     32// Deactivate any logging when we are not in debug mode
     33#ifdef NDEBUG
     34#undef LOG_OBSERVER
     35#endif
     36
    3037class Observable;
    3138class Notification;
     
    5865  template<class> friend class ObservedIterator;
    5966
    60 public:
    61   Observer();
     67  // indicates the constructor called from Observables
     68  struct BaseConstructor{};
     69
     70public:
     71  Observer(BaseConstructor);
     72  Observer(std::string);
    6273  virtual ~Observer();
    6374
     
    91102class Observable : public Observer {
    92103public:
    93   Observable();
     104  Observable(std::string _name);
    94105  virtual ~Observable();
    95106
     
    192203};
    193204
     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 */
     212class ObserverLog{
     213  friend class Observable;
     214  friend class Observer;
     215  template <typename> friend class Cacheable;
     216public:
     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*);
     222private:
     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
     234ObserverLog &observerLog();
     235
     236#endif
     237
    194238// extra macro is necessary to work with __LINE__
    195239#define PASTE(a,b) PASTE_HELPER(a,b)
  • src/Plane.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Plane.hpp"
     
    1416#include "Helpers/Assert.hpp"
    1517#include <cmath>
     18#include "Line.hpp"
     19#include "Exceptions/MultipleSolutionsException.hpp"
    1620
    1721/**
     
    4246/**
    4347 * Constructs a plane from two direction vectors and a offset.
    44  * If no offset is given a plane through origin is assumed
    4548 */
    4649Plane::Plane(const Vector &y1, const Vector &y2, double _offset) throw(ZeroVectorException,LinearDependenceException) :
     
    113116}
    114117
    115 Vector Plane::getOffsetVector() {
     118Vector Plane::getOffsetVector() const {
    116119  return getOffset()*getNormal();
    117120}
    118121
    119 vector<Vector> Plane::getPointsOnPlane(){
     122vector<Vector> Plane::getPointsOnPlane() const{
    120123  std::vector<Vector> res;
    121124  res.reserve(3);
     
    147150 * \return true -  \a this contains intersection point on return, false - line is parallel to plane (even if in-plane)
    148151 */
    149 Vector Plane::GetIntersection(const Vector &Origin, const Vector &LineVector)
     152Vector Plane::GetIntersection(const Line& line) const
    150153{
    151154  Info FunctionInfo(__func__);
    152155  Vector res;
    153156
    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());
    172170  double scaleFactor = (offset-factor2)/factor1;
    173171
    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.");
    182177  return res;
    183178};
     179
     180Vector 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
     186Line Plane::getOrthogonalLine(const Vector &origin) const{
     187  return Line(origin,getNormal());
     188}
    184189
    185190/************ Methods inherited from Space ****************/
  • src/Plane.hpp

    r980dd6 re6317b  
    1717
    1818class Vector;
     19class Line;
    1920
    2021class Plane : public Space
     
    4243   * Same as getOffset()*getNormal();
    4344   */
    44   Vector getOffsetVector();
     45  Vector getOffsetVector() const;
    4546
    4647  /**
    4748   * returns three seperate points on this plane
    4849   */
    49   std::vector<Vector> getPointsOnPlane();
     50  std::vector<Vector> getPointsOnPlane() const;
    5051
    5152  // 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;
    5364
    5465  /****** Methods inherited from Space ***********/
  • src/Space.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Space.hpp"
     
    1921}
    2022
     23Vector Space::getVectorToPoint(const Vector &origin) const{
     24  Vector support = getClosestPoint(origin);
     25  return support-origin;
     26}
     27
    2128bool Space::isContained(const Vector &point) const{
    2229  return (distance(point)) < MYEPSILON;
  • src/Space.hpp

    r980dd6 re6317b  
    1717  virtual ~Space();
    1818
     19  /**
     20   * Calculates the distance between a Space and a Vector.
     21   */
    1922  virtual double distance(const Vector &point) const=0;
     23
     24  /**
     25   * get the closest point inside the space to another point
     26   */
    2027  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   */
    2143  virtual bool isContained(const Vector &point) const;
     44
     45  /**
     46   * Tests if this space contains the center of the coordinate system.
     47   */
    2248  virtual bool hasZero() const;
    2349
  • src/UIElements/CommandLineUI/CommandLineDialog.cpp

    r980dd6 re6317b  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
    89
    910#include <iostream>
  • src/UIElements/CommandLineUI/CommandLineStatusIndicator.cpp

    r980dd6 re6317b  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
    89
    910#include "CommandLineUI/CommandLineStatusIndicator.hpp"
     
    1516using namespace std;
    1617
    17 CommandLineStatusIndicator::CommandLineStatusIndicator()
     18CommandLineStatusIndicator::CommandLineStatusIndicator() :
     19    Observer("CommandLineStatusIndicator")
    1820{
    1921  Process::AddObserver(this);
  • src/UIElements/CommandLineUI/CommandLineUIFactory.cpp

    r980dd6 re6317b  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
    89
    910#include "CommandLineUI/CommandLineUIFactory.hpp"
  • src/UIElements/CommandLineUI/CommandLineWindow.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <boost/bind.hpp>
  • src/UIElements/Dialog.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <cassert>
  • src/UIElements/MainWindow.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "MainWindow.hpp"
  • src/UIElements/Menu/ActionMenuItem.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
  • src/UIElements/Menu/DisplayMenuItem.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <sstream>
  • src/UIElements/Menu/Menu.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "Menu.hpp"
  • src/UIElements/Menu/MenuItem.cpp

    r980dd6 re6317b  
    66 */
    77
    8 
     8#include "Helpers/MemDebug.hpp"
    99
    1010#include "Menu/MenuItem.hpp"
  • src/UIElements/Menu/SeperatorItem.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
     9
    710#include <string>
    811#include <sstream>
  • src/UIElements/Menu/SubMenuItem.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "SubMenuItem.hpp"
  • src/UIElements/Menu/TextMenu.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <boost/bind.hpp>
  • src/UIElements/TextUI/TextDialog.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
  • src/UIElements/TextUI/TextStatusIndicator.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "TextUI/TextStatusIndicator.hpp"
     
    1416using namespace std;
    1517
    16 TextStatusIndicator::TextStatusIndicator()
     18TextStatusIndicator::TextStatusIndicator() :
     19  Observer("TextStatusIndicator")
    1720{
    1821  Process::AddObserver(this);
  • src/UIElements/TextUI/TextUIFactory.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "TextUI/TextUIFactory.hpp"
  • src/UIElements/TextUI/TextWindow.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "TextUI/TextWindow.hpp"
  • src/UIElements/UIFactory.cpp

    r980dd6 re6317b  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
    89
    910#include <cassert>
  • src/UIElements/Views/MethodStringView.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "MethodStringView.hpp"
  • src/UIElements/Views/StreamStringView.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <sstream>
  • src/UIElements/Views/StringView.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "StringView.hpp"
  • src/UIElements/Views/View.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "View.hpp"
  • src/World.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "World.hpp"
     
    276278
    277279World::World() :
     280    Observable("World"),
    278281    periode(new periodentafel),
    279282    configuration(new config),
  • src/analysis_bonds.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "analysis_bonds.hpp"
  • src/analysis_correlation.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
  • src/analyzer.cpp

    r980dd6 re6317b  
    77
    88//============================ INCLUDES ===========================
     9
     10#include "Helpers/MemDebug.hpp"
    911
    1012#include <cstring>
  • src/atom.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include "atom.hpp"
     
    1416#include "vector.hpp"
    1517#include "World.hpp"
     18#include "molecule.hpp"
    1619
    1720/************************************* Functions for class atom *************************************/
     
    2124 */
    2225atom::atom() :
    23   previous(NULL), next(NULL), father(this), sort(&nr)
     26  father(this), sort(&nr), mol(0)
    2427{
    2528  node = &x;  // TesselPoint::x can only be referenced from here
     
    2932 */
    3033atom::atom(atom *pointer) :
    31     ParticleInfo(pointer),
    32     previous(NULL), next(NULL), father(pointer), sort(&nr)
     34    ParticleInfo(pointer),father(pointer), sort(&nr)
    3335{
    3436  type = pointer->type;  // copy element of atom
     
    3739  FixedIon = pointer->FixedIon;
    3840  node = &x;
     41  mol = 0;
    3942};
    4043
    4144atom *atom::clone(){
    4245  atom *res = new atom(this);
    43   res->previous=0;
    44   res->next=0;
    4546  res->father = this;
    4647  res->sort = &res->nr;
     
    5051  res->FixedIon = FixedIon;
    5152  res->node = &x;
     53  res->mol = 0;
    5254  World::getInstance().registerAtom(res);
    5355  return res;
     
    5961atom::~atom()
    6062{
     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  }
    6169};
    6270
     
    6775atom *atom::GetTrueFather()
    6876{
    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  }
    7686};
    7787
     
    309319}
    310320
     321void 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
     330void atom::removeFromMolecule(){
     331  if(mol){
     332    if(mol->containsAtom(this)){
     333      mol->erase(this);
     334    }
     335    mol=0;
     336  }
     337}
     338
     339
    311340atom* NewAtom(atomId_t _id){
    312341  atom * res =new atom();
  • src/atom.hpp

    r980dd6 re6317b  
    3434class Vector;
    3535class World;
     36class molecule;
    3637
    3738/********************************************** declarations *******************************/
     
    4445  friend void  DeleteAtom(atom*);
    4546  public:
    46     atom *previous; //!< previous atom in molecule list
    47     atom *next;     //!< next atom in molecule list
    4847    atom *father;   //!< In many-body bond order fragmentations points to originating atom
    4948    int *sort;      //!< sort criteria
     
    8988   virtual void setId(atomId_t);
    9089
     90   void setMolecule(molecule*);
     91   void removeFromMolecule();
     92
    9193  protected:
     94
    9295    /**
    9396     * Protected constructor to ensure construction of atoms through the world.
     
    108111    virtual ~atom();
    109112  private:
     113    molecule *mol; // !< the molecule this atom belongs to
    110114    World* world;
    111115    atomId_t id;
  • src/atom_atominfo.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "periodentafel.hpp"
  • src/atom_bondedparticle.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom.hpp"
  • src/atom_bondedparticleinfo.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom_bondedparticleinfo.hpp"
  • src/atom_graphnode.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom_graphnode.hpp"
  • src/atom_graphnodeinfo.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom_graphnodeinfo.hpp"
  • src/atom_particleinfo.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom_particleinfo.hpp"
  • src/atom_trajectoryparticle.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom.hpp"
  • src/atom_trajectoryparticleinfo.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom_trajectoryparticleinfo.hpp"
  • src/bond.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include "atom.hpp"
  • src/bondgraph.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
  • src/boundary.cpp

    r980dd6 re6317b  
    33 * Implementations and super-function for envelopes
    44 */
     5
     6#include "Helpers/MemDebug.hpp"
    57
    68#include "World.hpp"
  • src/builder.cpp

    r980dd6 re6317b  
    4747 */
    4848
     49#include "Helpers/MemDebug.hpp"
    4950
    5051#include <boost/bind.hpp>
     
    8485#include "version.h"
    8586#include "World.hpp"
    86 #include "Helpers/MemDebug.hpp"
     87
    8788
    8889/********************************************* Subsubmenu routine ************************************/
     
    21902191  ActionRegistry::purgeInstance();
    21912192  ActionHistory::purgeInstance();
     2193#ifdef LOG_OBSERVER
     2194  cout << observerLog().getLog();
     2195#endif
    21922196  Memory::getState();
    21932197}
  • src/config.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include <stdio.h>
  • src/datacreator.cpp

    r980dd6 re6317b  
    66
    77//============================ INCLUDES ===========================
     8
     9#include "Helpers/MemDebug.hpp"
    810
    911#include "datacreator.hpp"
  • src/element.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include <iomanip>
  • src/elements_db.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810const char *elementsDB =\
  • src/ellipsoid.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <gsl/gsl_multimin.h>
  • src/errorlogger.cpp

    r980dd6 re6317b  
    55 *      Author: metzler
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <fstream>
  • src/graph.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79using namespace std;
  • src/gslmatrix.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810using namespace std;
  • src/gslvector.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <cassert>
  • src/helpers.cpp

    r980dd6 re6317b  
    44 */
    55
     6#include "Helpers/MemDebug.hpp"
    67
    78#include "helpers.hpp"
  • src/info.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "info.hpp"
  • src/joiner.cpp

    r980dd6 re6317b  
    77
    88//============================ INCLUDES ===========================
     9
     10#include "Helpers/MemDebug.hpp"
    911
    1012#include <cstring>
  • src/leastsquaremin.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
  • src/linearsystemofequations.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "defs.hpp"
  • src/linkedcell.cpp

    r980dd6 re6317b  
    55 */
    66
     7#include "Helpers/MemDebug.hpp"
    78
    89#include "atom.hpp"
  • src/log.cpp

    r980dd6 re6317b  
    55 *      Author: metzler
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "logger.hpp"
  • src/logger.cpp

    r980dd6 re6317b  
    55 *      Author: metzler
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <fstream>
  • src/memoryallocator.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810using namespace std;
  • src/memoryusageobserver.cpp

    r980dd6 re6317b  
    44 * This class represents a Singleton for observing memory usage.
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include <cstdlib>
  • src/molecule.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include <cstring>
     
    3537 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3638 */
    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())
     39molecule::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())
    4345{
    4446
     
    143145  molecule::const_iterator iter = loc;
    144146  iter--;
     147  atom* atom = *loc;
    145148  atoms.erase( loc );
     149  atom->removeFromMolecule();
    146150  return iter;
    147151}
    148152
    149 molecule::const_iterator molecule::erase( atom *& key )
     153molecule::const_iterator molecule::erase( atom * key )
    150154{
    151155  cout << "trying to erase atom" << endl;
    152156  molecule::const_iterator iter = find(key);
    153157  if (iter != end()){
    154     // remove this position and step forward (post-increment)
    155158    atoms.erase( iter++ );
     159    key->removeFromMolecule();
    156160  }
    157161  return iter;
    158162}
    159163
    160 molecule::const_iterator molecule::find ( atom *& key ) const
     164molecule::const_iterator molecule::find ( atom * key ) const
    161165{
    162166  return atoms.find( key );
     
    167171  pair<atomSet::iterator,bool> res = atoms.insert(key);
    168172  return pair<iterator,bool>(iterator(res.first,this),res.second);
     173}
     174
     175bool molecule::containsAtom(atom* key){
     176  return atoms.count(key);
    169177}
    170178
     
    192200    }
    193201    insert(pointer);
     202    pointer->setMolecule(this);
    194203  }
    195204  return true;
     
    657666bond * molecule::AddBond(atom *atom1, atom *atom2, int degree)
    658667{
     668  OBSERVE;
    659669  bond *Binder = NULL;
    660670
  • src/molecule.hpp

    r980dd6 re6317b  
    153153  size_t size() const;
    154154  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;
    157157  pair<iterator,bool> insert ( atom * const key );
     158  bool containsAtom(atom* key);
    158159
    159160
  • src/molecule_dynamics.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "World.hpp"
  • src/molecule_fragmentation.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <cstring>
  • src/molecule_geometry.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom.hpp"
     
    1618#include "molecule.hpp"
    1719#include "World.hpp"
     20#include "Plane.hpp"
     21#include <boost/foreach.hpp>
     22
    1823
    1924/************************************* Functions for class molecule *********************************/
     
    256261void molecule::Mirror(const Vector *n)
    257262{
    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  }
    259268};
    260269
  • src/molecule_graph.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom.hpp"
  • src/molecule_pointcloud.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "atom.hpp"
  • src/moleculelist.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include <cstring>
     
    2931 */
    3032MoleculeListClass::MoleculeListClass(World *_world) :
     33  Observable("MoleculeListClass"),
    3134  world(_world)
    3235{
  • src/parser.cpp

    r980dd6 re6317b  
    66
    77// ======================================= INCLUDES ==========================================
     8
     9#include "Helpers/MemDebug.hpp"
    810
    911#include <cstring>
  • src/periodentafel.cpp

    r980dd6 re6317b  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79using namespace std;
  • src/tesselation.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <fstream>
     
    1719#include "triangleintersectionlist.hpp"
    1820#include "vector.hpp"
     21#include "Line.hpp"
    1922#include "vector_ops.hpp"
    2023#include "verbose.hpp"
     
    441444
    442445  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);
    473469      helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
    474470      CrossPoint -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     
    477473      if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
    478474        DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
    479         i=4;
    480         break;
     475        return false;
    481476      }
    482477      i++;
    483     } catch (LinearDependenceException &excp){
    484       break;
    485     }
    486   } while (i < 3);
    487   if (i == 3) {
     478    } while (i < 3);
    488479    DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
    489480    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);
    492485    return false;
    493486  }
     
    516509  GetCenter(&Direction);
    517510  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) {
    521515    (*ClosestPoint) = (*x);
    522516  }
     
    541535    Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
    542536    // 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);
    544539    CrossDirection[i] = CrossPoint[i] - InPlane;
    545540    CrossPoint[i] -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
  • src/tesselationhelpers.cpp

    r980dd6 re6317b  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <fstream>
     
    1416#include "tesselationhelpers.hpp"
    1517#include "vector.hpp"
     18#include "Line.hpp"
    1619#include "vector_ops.hpp"
    1720#include "verbose.hpp"
     
    666669  // calculate the intersection between this projected baseline and Base
    667670  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);
    671674  Normal = (*Intersection) - (*Base->endpoints[0]->node->node);
    672675  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  
    88 *      Author: heber
    99 */
     10
     11#include "Helpers/MemDebug.hpp"
    1012
    1113#include "triangleintersectionlist.hpp"
  • src/unittests/CacheableTest.cpp

    r980dd6 re6317b  
    5555
    5656  threeNumbers(int _x,int _y, int _z) :
     57    Observable("threeNumbers"),
    5758    x(_x),y(_y),z(_z),
    58     sum(this,boost::bind(&threeNumbers::calcSum,this)),
     59    sum(this,boost::bind(&threeNumbers::calcSum,this),"sum"),
    5960    hasRecalced(false)
    6061  {}
     
    8182  CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum));
    8283  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
    8391}
  • src/unittests/Makefile.am

    r980dd6 re6317b  
    2626  InfoUnitTest \
    2727  LinearSystemOfEquationsUnitTest \
     28  LineUnittest \
    2829  LinkedCellUnitTest \
    2930  ListOfBondsUnitTest \
     
    6970  infounittest.cpp \
    7071  linearsystemofequationsunittest.cpp \
     72  LineUnittest.cpp \
    7173  LinkedCellUnitTest.cpp \
    7274  listofbondsunittest.cpp \
     
    104106  infounittest.hpp \
    105107  linearsystemofequationsunittest.hpp \
     108  LineUnittest.hpp \
    106109  LinkedCellUnitTest.hpp \
    107110  listofbondsunittest.hpp \
     
    170173LinearSystemOfEquationsUnitTest_LDADD = ${ALLLIBS}
    171174
     175LineUnittest_SOURCES = UnitTestMain.cpp LineUnittest.cpp LineUnittest.hpp
     176LineUnittest_LDADD = ${ALLLIBS}
     177
    172178LinkedCellUnitTest_SOURCES = UnitTestMain.cpp LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp
    173179LinkedCellUnitTest_LDADD = ${ALLLIBS}
  • src/unittests/ObserverTest.cpp

    r980dd6 re6317b  
    3333public:
    3434  UpdateCountObserver() :
     35    Observer("UpdateCountObserver"),
    3536    updates(0)
    3637  {};
     
    4546class SimpleObservable : public Observable {
    4647public:
     48  SimpleObservable() :
     49    Observable("SimpleObservable")
     50  {}
     51
    4752  void changeMethod() {
    4853    OBSERVE;
     
    5459class CallObservable : public Observable {
    5560public:
     61  CallObservable() :
     62    Observable("CallObservable")
     63  {}
     64
    5665  void changeMethod1() {
    5766    OBSERVE;
     
    7079class BlockObservable : public Observable {
    7180public:
     81  BlockObservable() :
     82    Observable("BlockObservable")
     83  {}
     84
    7285  void changeMethod1(){
    7386    OBSERVE;
     
    104117class SuperObservable : public Observable {
    105118public:
    106   SuperObservable(){
     119  SuperObservable():
     120    Observable("SuperObservable")
     121  {
    107122    subObservable = new SimpleObservable();
    108123    subObservable->signOn(this);
     
    123138public:
    124139  NotificationObservable() :
    125       notification1(new Notification(this)),
    126       notification2(new Notification(this))
     140    Observable("NotificationObservable"),
     141    notification1(new Notification(this)),
     142    notification2(new Notification(this))
    127143  {}
    128144
     
    149165public:
    150166  NotificationObserver(Notification_ptr notification) :
     167    Observer("NotificationObserver"),
    151168    requestedNotification(notification),
    152169    wasNotified(false)
     
    172189
    173190  ObservableCollection(int _num) :
    174   num(_num)
     191    Observable("ObservableCollection"),
     192    num(_num)
    175193  {
    176194    for(int i=0; i<num; ++i){
  • src/unittests/PlaneUnittest.cpp

    r980dd6 re6317b  
    1717
    1818#include "vector.hpp"
     19#include "Line.hpp"
    1920
    2021CPPUNIT_TEST_SUITE_REGISTRATION( PlaneUnittest );
     
    153154  CPPUNIT_ASSERT(fabs(p4->distance(e1)-1) < MYEPSILON);
    154155  CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(e1));
    155 
    156 
    157 }
     156}
     157
     158void 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
     205void 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  
    2020  CPPUNIT_TEST ( pointsTest );
    2121  CPPUNIT_TEST ( operationsTest );
     22  CPPUNIT_TEST ( mirrorTest );
     23  CPPUNIT_TEST ( LineIntersectionTest );
    2224  CPPUNIT_TEST_SUITE_END();
    2325
     
    3032  void pointsTest();
    3133  void operationsTest();
     34  void mirrorTest();
     35  void LineIntersectionTest();
    3236
    3337private:
  • src/unittests/listofbondsunittest.cpp

    r980dd6 re6317b  
    249249void ListOfBondsTest::DeleteAtomTest()
    250250{
    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() );
    262271
    263272  // remove atom2
     
    268277
    269278  // 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  
    5555public:
    5656  countObserver() :
     57    Observer("countObserver"),
    5758    count(0)
    5859    {}
  • src/unittests/vectorunittest.cpp

    r980dd6 re6317b  
    215215}
    216216
    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 zero
    230   CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException);
    231   //CPPUNIT_ASSERT_EQUAL( zero, fixture );
    232 
    233   // four vectors equal to unit
    234   CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException);
    235   //CPPUNIT_ASSERT_EQUAL( zero, fixture );
    236 
    237   // two equal lines
    238   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 change
    261   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 change
    268   fixture = RotateVector(unit,unit, 1.);
    269   CPPUNIT_ASSERT_EQUAL( unit, fixture );
    270 
    271   // rotations
    272   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 }
    284217
    285218/**
  • src/unittests/vectorunittest.hpp

    r980dd6 re6317b  
    2727    CPPUNIT_TEST ( ProjectionTest );
    2828    CPPUNIT_TEST ( NormalsTest );
    29     CPPUNIT_TEST ( LineIntersectionTest );
    30     CPPUNIT_TEST ( VectorRotationTest );
    3129    CPPUNIT_TEST ( IsInParallelepipedTest );
    3230    CPPUNIT_TEST_SUITE_END();
  • src/vector.cpp

    r980dd6 re6317b  
    55 */
    66
     7#include "Helpers/MemDebug.hpp"
    78
    89#include "vector.hpp"
     
    213214{
    214215  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];
    218219  (*this) = tmp;
    219220};
     
    232233  *this -= tmp;
    233234};
    234 
    235 /** Calculates the minimum distance vector of this vector to the plane.
    236  * \param *out output stream for debugging
    237  * \param *PlaneNormal normal of plane
    238  * \param *PlaneOffset offset of plane
    239  * \return distance to plane
    240  * \return distance vector onto to plane
    241  */
    242 Vector Vector::GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const
    243 {
    244   Vector temp = (*this) - PlaneOffset;
    245   temp.MakeNormalTo(PlaneNormal);
    246   temp.Scale(-1.);
    247   // then add connecting vector from plane to point
    248   temp += (*this)-PlaneOffset;
    249   double sign = temp.ScalarProduct(PlaneNormal);
    250   if (fabs(sign) > MYEPSILON)
    251     sign /= fabs(sign);
    252   else
    253     sign = 0.;
    254 
    255   temp.Normalize();
    256   temp.Scale(sign);
    257   return temp;
    258 };
    259 
    260235
    261236/** Calculates the minimum distance of this vector to the plane.
     
    551526  MatrixMultiplication(M);
    552527};
     528
     529std::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
     535std::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}
    553545
    554546/** Do a matrix multiplication.
     
    611603};
    612604
    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 one
    621   for (int i=NDIM;i--;)
    622     at(i) -= 2.*projection*n[i];
    623 };
    624 
    625605/** Calculates orthonormal vector to one given vectors.
    626606 * Just subtracts the projection onto the given vector from this vector.
     
    633613  bool result = false;
    634614  double factor = y1.ScalarProduct(*this)/y1.NormSquared();
    635   Vector x1;
    636   x1 = factor * y1;
     615  Vector x1 = factor * y1;
    637616  SubtractVector(x1);
    638617  for (int i=NDIM;i--;)
  • src/vector.hpp

    r980dd6 re6317b  
    1616
    1717#include <memory>
     18#include <vector>
    1819
    1920#include "defs.hpp"
     
    2122
    2223/********************************************** declarations *******************************/
     24
     25class Vector;
     26
     27typedef std::vector<Vector> pointset;
    2328
    2429/** Single vector.
     
    3944
    4045  double DistanceSquared(const Vector &y) const;
    41   Vector GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
    4246  double DistanceToSpace(const Space& space) const;
    4347  double PeriodicDistance(const Vector &y, const double * const cell_size) const;
     
    5660  void ProjectIt(const Vector &y);
    5761  Vector Projection(const Vector &y) const;
    58   void Mirror(const Vector &x);
    5962  void ScaleAll(const double *factor);
    6063  void Scale(const double factor);
     
    6669  bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
    6770  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;
    6873
    6974  // Accessors ussually come in pairs... and sometimes even more than that
  • src/vector_ops.cpp

    r980dd6 re6317b  
    55 *      Author: crueger
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include "vector.hpp"
     
    1517#include "Helpers/fast_functions.hpp"
    1618#include "Exceptions/LinearDependenceException.hpp"
     19#include "Exceptions/SkewException.hpp"
    1720
    1821#include <gsl/gsl_linalg.h>
     
    110113  return true;
    111114};
    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 axis
    115  * \param alpha rotation angle in radian
    116  */
    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 axis
    122   a = vec;
    123   a.ProjectOntoPlane(axis);
    124   // construct normal vector
    125   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 cosine
    135   y.Scale(sin(alpha));
    136   a.Scale(cos(alpha));
    137   res = vec.Projection(axis);
    138   // add scaled normal vector onto this vector
    139   res += y;
    140   // add part in axis direction
    141   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.html
    147  * \param *out output stream for debugging
    148  * \param *Line1a first vector of first line
    149  * \param *Line1b second vector of first line
    150  * \param *Line2a first vector of second line
    151  * \param *Line2b second vector of second line
    152  * \return true - \a this will contain the intersection on return, false - lines are parallel
    153  */
    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,c
    185   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 parallelity
    197   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 s
    221   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   else
    231     s = 0.;
    232   Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;
    233 
    234   // construct intersection
    235   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  
    1010
    1111bool 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);
    1412
    1513#endif /* VECTOR_OPS_HPP_ */
  • src/verbose.cpp

    r980dd6 re6317b  
    11using namespace std;
     2
     3#include "Helpers/MemDebug.hpp"
    24
    35#include "info.hpp"
Note: See TracChangeset for help on using the changeset viewer.