bool ManifoldManager::removeAndCheckManifoldness(Delaunay3::Cell_handle &currentTet, int curIdx) {
  std::vector<Delaunay3::Cell_handle> incidentCells, cellsModified;
  std::vector<Delaunay3::Vertex_handle> incidentV;
  Delaunay3::Vertex_handle curV = currentTet->vertex(curIdx);
  dt_.incident_cells(curV, std::back_inserter(incidentCells));
  dt_.adjacent_vertices(curV, std::back_inserter(incidentV));
  bool wrong = false;

  bool foundNotFreespace = false;
  for (auto ic : incidentCells) {
    if (isFreespace(ic)) {
      if (!ic->info().iskeptManifold()) {
        cellsModified.push_back(ic);
        ic->info().setKeptManifold(true);
      }
    } else {
      //foundNotFreespace = true;
    }
  }

  /*if (foundNotFreespace) {
   for (auto ic : cellsModified) {
   ic->info().setKeptManifold(false);
   }
   return false;
   }
   */
  int count = 0;
  for (auto iv : incidentV) {

    if (!isRegular(iv)) {
      wrong = true;
    }
  }
  if (!isRegular(curV)) {
    wrong = true;
  }

  if (wrong) {
    for (auto ic : cellsModified) {
      ic->info().setKeptManifold(false);
    }
    return false;
  } else {
    for (auto ic : cellsModified) {
      ic->info().setKeptManifold(false);
    }


    int i=0;
    for (auto ic : cellsModified) {

      addTetAndUpdateBoundary(ic);
    }
  }

  return true;
}
bool ManifoldManager::checkManifoldness(Delaunay3::Cell_handle &cellToTest1, int idxNeigh) {
  Delaunay3::Vertex_handle v = cellToTest1->vertex(idxNeigh);
  Delaunay3::Cell_handle curTetNeigh = cellToTest1->neighbor(idxNeigh);

  if (!isRegular(v))
    return false;

  for (int curNei = 0; curNei < 4; ++curNei) {
    Delaunay3::Vertex_handle vC = curTetNeigh->vertex(curNei);

    if (!isRegular(vC))
      return false;
  }
  return true;
}
Example #3
0
int main(int argc, char** argv) {
    
    GRAPH graph;
    ADJACENCY adj;
    
    int graphsRead = 0;
    int graphsFiltered = 0;

    /*=========== commandline parsing ===========*/

    int c;
    char *name = argv[0];
    static struct option long_options[] = {
        {"k-regular", required_argument, NULL, 'k'},
        {"count", no_argument, NULL, 'c'},
        {"help", no_argument, NULL, 'h'}
    };
    int option_index = 0;

    while ((c = getopt_long(argc, argv, "hk:c", long_options, &option_index)) != -1) {
        switch (c) {
            case 'k':
                kRegular = TRUE;
                k = atoi(optarg);
                break;
            case 'c':
                onlyCount = TRUE;
                break;
            case 'h':
                help(name);
                return EXIT_SUCCESS;
            case '?':
                usage(name);
                return EXIT_FAILURE;
            default:
                fprintf(stderr, "Illegal option %c.\n", c);
                usage(name);
                return EXIT_FAILURE;
        }
    }
    
    unsigned short code[MAXCODELENGTH];
    int length;
    while (readMultiCode(code, &length, stdin)) {
        decodeMultiCode(code, length, graph, adj);
        graphsRead++;
        
        if(isRegular(graph, adj)){
            if(!onlyCount){
                writeMultiCode(graph, adj, stdout);
            }
            graphsFiltered++;
        }
    }
    
    fprintf(stderr, "Read %d graph%s.\n", graphsRead, graphsRead==1 ? "" : "s");
    fprintf(stderr, "Filtered %d graph%s.\n", graphsFiltered, graphsFiltered==1 ? "" : "s");

    return (EXIT_SUCCESS);
}
void
SourceFileModel::updateSelectionStatus() {
  m_nonAppendedSelected    = false;
  m_appendedSelected       = false;
  m_additionalPartSelected = false;

  auto selectionModel      = qobject_cast<QItemSelectionModel *>(QObject::sender());
  Q_ASSERT(selectionModel);

  Util::withSelectedIndexes(selectionModel, [this](QModelIndex const &selectedIndex) {
    auto sourceFile = fromIndex(selectedIndex);
    Q_ASSERT(!!sourceFile);

    if (sourceFile->isRegular())
      m_nonAppendedSelected = true;

    else if (sourceFile->isAppended())
      m_appendedSelected = true;

    else if (sourceFile->isAdditionalPart())
      m_additionalPartSelected = true;
  });

  mxinfo(boost::format("file sel changed nonApp %1% app %2% addPart %3%\n") % m_nonAppendedSelected % m_appendedSelected % m_additionalPartSelected);
}
Example #5
0
  bool IpoptInternal::eval_grad_f(int n, const double* x, bool new_x, double* grad_f)
  {
    try {
      log("eval_grad_f started");
      double time1 = clock();
      casadi_assert(n == nx_);
    
      // Pass the argument to the function
      gradF_.setInput(x,NL_X);
      gradF_.setInput(input(NLP_SOLVER_P),NL_P);
      
      // Evaluate, adjoint mode
      gradF_.evaluate();
      
      // Get the result
      gradF_.output().getArray(grad_f,n,DENSE);
      
      // Printing
      if(monitored("eval_grad_f")){
        cout << "x = " << gradF_.input(NL_X) << endl;
        cout << "grad_f = " << gradF_.output() << endl;
      }

      if (regularity_check_ && !isRegular(gradF_.output().data())) casadi_error("IpoptInternal::grad_f: NaN or Inf detected.");
    
      double time2 = clock();
      t_eval_grad_f_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_grad_f_ += 1;
      log("eval_grad_f ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_grad_f failed: " << ex.what() << endl;
      return false;
    }
  }
Example #6
0
GeometryService::InOut SlabService::InsideOutside(const Box&           a_region,
                                                  const ProblemDomain& a_domain,
                                                  const RealVect&      a_origin,
                                                  const Real&          a_dx) const
{
  if (isRegular(a_region, a_domain, a_origin, a_dx)) return GeometryService::Regular;
  if (isCovered(a_region, a_domain, a_origin, a_dx)) return GeometryService::Covered;
  return GeometryService::Irregular;
}
Example #7
0
	ReturnCode Library::ctor_(File fn)
	{
		MSS_BEGIN(ReturnCode);
		MSS(resolve(fn));
		MSS(isRegular(fn));
        Handle h;
        MSS(load_(h, fn.name()));
		pimpl_.reset(new Pimpl(h, fn));
		MSS_END();
	}
Example #8
0
  bool IpoptInternal::eval_jac_g(int n, const double* x, bool new_x,int m, int nele_jac, int* iRow, int *jCol,double* values){
    try{
      log("eval_jac_g started");
    
      // Quich finish if no constraints
      if(m==0){
        log("eval_jac_g quick return (m==0)");
        return true;
      }
      
      // Get function
      Function& jacG = this->jacG();
    
      double time1 = clock();
      if (values == NULL) {
        int nz=0;
        const vector<int>& colind = jacG.output().colind();
        const vector<int>& row = jacG.output().row();
        for(int cc=0; cc<colind.size()-1; ++cc)
          for(int el=colind[cc]; el<colind[cc+1]; ++el){
            int rr = row[el];
            iRow[nz] = rr;
            jCol[nz] = cc;
            nz++;
          }
      } else {
        // Pass the argument to the function
        jacG.setInput(x,NL_X);
        jacG.setInput(input(NLP_SOLVER_P),NL_P);
      
        // Evaluate the function
        jacG.evaluate();

        // Get the output
        jacG.getOutput(values);
      
        if(monitored("eval_jac_g")){
          cout << "x = " << jacG.input(NL_X).data() << endl;
          cout << "J = " << endl;
          jacG.output().printSparse();
        }
        if (regularity_check_ && !isRegular(jacG.output().data())) casadi_error("IpoptInternal::jac_g: NaN or Inf detected.");
      }
    
      double time2 = clock();
      t_eval_jac_g_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_jac_g_ += 1;
      log("eval_jac_g ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_jac_g failed: " << ex.what() << endl;
      return false;
    }
  }
Example #9
0
  bool WorhpInternal::eval_grad_f(const double* x, double scale , double* grad_f )
  {
    try {
      log("eval_grad_f started");
      double time1 = clock();
    
      // Pass the argument to the function
      gradF_.setInput(x,NL_X);
      gradF_.setInput(input(NLP_SOLVER_P),NL_P);
      
      // Evaluate, adjoint mode
      gradF_.evaluate();
      
      // Get the result
      gradF_.output().get(grad_f,DENSE);

      // Scale
      for(int i=0; i<nx_; ++i){
        grad_f[i] *= scale;
      }
      
      // Printing
      if(monitored("eval_grad_f")){
        cout << "grad_f = " << gradF_.output() << endl;
      }
      
      if (regularity_check_ && !isRegular(gradF_.output().data())) casadi_error("WorhpInternal::eval_grad_f: NaN or Inf detected.");
    
      double time2 = clock();
      t_eval_grad_f_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_grad_f_ += 1;
      // Check the result for regularity
      for(int i=0; i<nx_; ++i){
        if(isnan(grad_f[i]) || isinf(grad_f[i])){
          log("eval_grad_f: result not regular");
          return false;
        }
      }

      log("eval_grad_f ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_jac_f failed: " << ex.what() << endl;
      return false;
    }
  }
Example #10
0
  bool IpoptInternal::eval_h(const double* x, bool new_x, double obj_factor, const double* lambda,bool new_lambda, int nele_hess, int* iRow,int* jCol, double* values){
    try{
      log("eval_h started");
      double time1 = clock();
      if (values == NULL) {
        int nz=0;
        const vector<int>& colind = hessLag_.output().colind();
        const vector<int>& row = hessLag_.output().row();
        for(int cc=0; cc<colind.size()-1; ++cc)
          for(int el=colind[cc]; el<colind[cc+1] && row[el]<=cc; ++el){
            iRow[nz] = row[el];
            jCol[nz] = cc;
            nz++;
          }
      } else {
        // Pass the argument to the function
        hessLag_.setInput(x,NL_X);
        hessLag_.setInput(input(NLP_SOLVER_P),NL_P);
        hessLag_.setInput(obj_factor,NL_NUM_IN+NL_F);
        hessLag_.setInput(lambda,NL_NUM_IN+NL_G);
        
        // Evaluate
        hessLag_.evaluate();

        // Get results
        hessLag_.output().get(values,SPARSESYM);
      
        if(monitored("eval_h")){
          cout << "x = " << hessLag_.input(NL_X).data() << endl;
          cout << "H = " << endl;
          hessLag_.output().printSparse();
        }
        
        if (regularity_check_ && !isRegular(hessLag_.output().data())) casadi_error("IpoptInternal::h: NaN or Inf detected.");
      
      }
      double time2 = clock();
      t_eval_h_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_h_ += 1;
      log("eval_h ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_h failed: " << ex.what() << endl;
      return false;
    }
  }
void
SourceFile::fixAssociations(MuxConfig::Loader &l) {
  if (isRegular())
    m_appendedTo = nullptr;

  else {
    auto appendedToID = reinterpret_cast<qulonglong>(m_appendedTo);
    if ((0 >= appendedToID) || !l.objectIDToSourceFile.contains(appendedToID))
      throw mtx::InvalidSettingsX{};
    m_appendedTo = l.objectIDToSourceFile.value(appendedToID);
  }

  for (auto &track : m_tracks)
    track->m_file = this;

  fixAssociationsFor("tracks",          m_tracks,          l);
  fixAssociationsFor("additionalParts", m_additionalParts, l);
  fixAssociationsFor("appendedFiles",   m_appendedFiles,   l);
}
Example #12
0
void readable(char* path){
	if ((access(path, R_OK))){return;}
	DIR* current;
	current = opendir(path);	
	char* nextPath;
	struct dirent *d;
	d = readdir(current);

		
		while(d){	

			if(!(strcmp(d->d_name, ".")) || !(strcmp(d->d_name, ".."))){
				d = readdir(current);
				continue;
			}

			nextPath = calloc(4096, sizeof(char));
			strcpy(nextPath, path);
			strcat(nextPath, "/");
			strcat(nextPath, d->d_name);
			if ((access(nextPath, R_OK))){
				d = readdir(current);
				continue;
			}

				if(isDirectory(nextPath)){
					//printf("%s/%s is a directory \n", path, d->d_name);
					readable(nextPath);
					d = readdir(current);
					continue;

				}else if(isRegular(nextPath)){
					if (access(d->d_name, R_OK));
					printf("%s/%s is readable\n", path, d->d_name);
				}
			
			d = readdir(current);
			free(nextPath);
		}	
	return;
}
Example #13
0
  bool IpoptInternal::eval_f(int n, const double* x, bool new_x, double& obj_value)
  {
    try {
      log("eval_f started");
    
      // Log time
      double time1 = clock();
      casadi_assert(n == nx_);

      // Pass the argument to the function
      nlp_.setInput(x,NL_X);
      nlp_.setInput(input(NLP_SOLVER_P),NL_P);
      
      // Evaluate the function
      nlp_.evaluate();

      // Get the result
      nlp_.getOutput(obj_value,NL_F);

      // Printing
      if(monitored("eval_f")){
        cout << "x = " << nlp_.input(NL_X) << endl;
        cout << "obj_value = " << obj_value << endl;
      }

      if (regularity_check_ && !isRegular(nlp_.output(NL_F).data())) casadi_error("IpoptInternal::f: NaN or Inf detected.");
    
      double time2 = clock();
      t_eval_f_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_f_ += 1;
      log("eval_f ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_f failed: " << ex.what() << endl;
      return false;
    }
    
  }
Example #14
0
  bool WorhpInternal::eval_g(const double* x, double* g)
  {
    try {
      log("eval_g started");
      double time1 = clock();

      if(worhp_o_.m>0){
        // Pass the argument to the function
        nlp_.setInput(x,NL_X);
        nlp_.setInput(input(NLP_SOLVER_P),NL_P);

        // Evaluate the function and tape
        nlp_.evaluate();

        // Ge the result
        nlp_.getOutput(g,NL_G);

        // Printing
        if(monitored("eval_g")){
          cout << "x = " << nlp_.input(NL_X) << endl;
          cout << "g = " << nlp_.output(NL_G) << endl;
        }
      }

      if (regularity_check_ && !isRegular(nlp_.output(NL_G).data())) casadi_error("WorhpInternal::eval_g: NaN or Inf detected.");
    
      double time2 = clock();
      t_eval_g_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_g_ += 1;
      log("eval_g ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_g failed: " << ex.what() << endl;
      return false;
    }
  }
Example #15
0
void
SourceFileModel::updateSelectionStatus() {
  m_nonAppendedSelected    = false;
  m_appendedSelected       = false;
  m_additionalPartSelected = false;

  auto selectionModel      = qobject_cast<QItemSelectionModel *>(QObject::sender());
  Q_ASSERT(selectionModel);

  Util::withSelectedIndexes(selectionModel, [this](QModelIndex const &selectedIndex) {
    auto sourceFile = fromIndex(selectedIndex);
    if (!sourceFile)
      return;

    if (sourceFile->isRegular())
      m_nonAppendedSelected = true;

    else if (sourceFile->isAppended())
      m_appendedSelected = true;

    else if (sourceFile->isAdditionalPart())
      m_additionalPartSelected = true;
  });
}
Example #16
0
  bool WorhpInternal::eval_h(const double* x, double obj_factor, const double* lambda, double* values){
    try{
      log("eval_h started");
      double time1 = clock();

      // Make sure generated
      casadi_assert_warning(!hessLag_.isNull(),"Hessian function not pregenerated");

      // Get Hessian 
      Function& hessLag = this->hessLag();

      // Pass input
      hessLag.setInput(x,HESSLAG_X);
      hessLag.setInput(input(NLP_SOLVER_P),HESSLAG_P);
      hessLag.setInput(obj_factor,HESSLAG_LAM_F);
      hessLag.setInput(lambda,HESSLAG_LAM_G);

      // Evaluate
      hessLag.evaluate();

      // Get results
      const DMatrix& H = hessLag.output();
      const vector<int>& colind = H.colind();
      const vector<int>& row = H.row();
      const vector<double>& data = H.data();

      // The Hessian values are divided into strictly upper (in WORHP lower) triangular and diagonal
      double* values_upper = values;
      double* values_diagonal = values + (worhp_w_.HM.nnz-nx_);

      // Initialize diagonal to zero
      for(int r=0; r<nx_; ++r){
        values_diagonal[r] = 0.;
      }

      // Upper triangular part of the Hessian (note CCS -> CRS format change)
      for(int c=0; c<nx_; ++c){
        for(int el=colind[c]; el<colind[c+1]; ++el){
          if(row[el]>c){
            // Strictly upper triangular
            *values_upper++ = data[el];
          } else if(row[el]==c){
            // Diagonal separately
            values_diagonal[c] = data[el];
          }
        }
      }
      
      if(monitored("eval_h")){
        std::cout << "x = " <<  hessLag.input(HESSLAG_X) << std::endl;
        std::cout << "obj_factor= " << obj_factor << std::endl;
        std::cout << "lambda = " << hessLag.input(HESSLAG_LAM_G) << std::endl;
        std::cout << "H = " << hessLag.output(HESSLAG_HESS) << std::endl;
      }

      if (regularity_check_ && !isRegular(hessLag.output(HESSLAG_HESS).data())) casadi_error("WorhpInternal::eval_h: NaN or Inf detected.");
      
      double time2 = clock();
      t_eval_h_ += double(time2-time1)/CLOCKS_PER_SEC;
      n_eval_h_ += 1;
      log("eval_h ok");
      return true;
    } catch (exception& ex){
      cerr << "eval_h failed: " << ex.what() << endl;
      return false;
    }
  }