MaterialFactory.cpp 1.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
// This file is a part of nla3d project. For information about authors and
// licensing go to project's repository on github:
// https://github.com/dmitryikh/nla3d 

#include "materials/MaterialFactory.h"

namespace nla3d {

const char* const MaterialFactory::matModelLabels[]={"UNDEFINED",
  "Neo-Hookean",
  "Biderman",
  "Mooney-Rivlin"
};

MaterialFactory::matId MaterialFactory::matName2matId (std::string matName) {
  for (uint16 i = 0; i < MaterialFactory::LAST; i++) {
    if (matName.compare(MaterialFactory::matModelLabels[i]) == 0) {
      return (MaterialFactory::matId) i;
    }
  }
  return MaterialFactory::NOT_DEFINED;
}

Material* MaterialFactory::createMaterial (std::string matName) {
  uint16 matId = matName2matId(matName);
  Material* mat;
  if (matId == MaterialFactory::NOT_DEFINED) {
    LOG(ERROR) << "Can't find material " << matName;
    return nullptr;
  }
  switch (matId) {
    case MaterialFactory::NEO_HOOKEAN_COMP:
      mat = new Mat_Comp_Neo_Hookean();
      break;
    case MaterialFactory::BIDERMAN_COMP:
      mat = new Mat_Comp_Biderman();
      break;
    case MaterialFactory::MOONEYRIVLIN_COMP:
      mat = new Mat_Comp_MooneyRivlin();
      break;
    default:
      LOG(ERROR) << "Don't have a material with id  = " << matId;
      return nullptr;
  }
  mat->code = matId;
  return mat;
}

} // namespace nla3d