// ---------------------------------------------------------------
// class to find paths for adventure map
// find some point, any point, which needs to be have a path cleared
// ---------------------------------------------------------------
bool t_combat_obstruction_finder::find_obstruction( t_map_point_2d& result ) 
{
	// find an obstructed point
	t_potential_creature creature(2);
	t_map_point_2d      point;
	t_map_point_2d      nearby_point;
	int                 row_end;
	t_combat_path_data* ptr;

	generate_paths();
	point.row = m_data.get_size();
	while (point.row--)
	{
		point.column = m_data.get_row_start( point.row );
		row_end = m_data.get_row_end( point.row );
		ptr = &m_data.get( point );
		while (point.column < row_end)
		{
			if ((ptr->move_cost > 0 || ptr->off_map || ptr->forbidden)
				&& m_battlefield.can_place( creature, point ))
			{
				result = find_closest_point( point );
				if (m_data.get( result ).move_cost > 0)
					return true;
			}
			ptr++;
			point.column++;
		}
	}
	return false;
}
Exemple #2
0
void passive_motion(int x, int y)
{
  static int cur_cursor = GLUT_CURSOR_LEFT_ARROW;

  /* which_point contains the point that the mouse is closest to */
  /* -1 if not close to any point */
  which_point = find_closest_point(x,y);

  if(which_point < 0 && cur_cursor == GLUT_CURSOR_CROSSHAIR) {
    glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
    cur_cursor = GLUT_CURSOR_LEFT_ARROW;
  }

  else if(which_point >=0 && cur_cursor == GLUT_CURSOR_LEFT_ARROW) {
    glutSetCursor(GLUT_CURSOR_CROSSHAIR);
    cur_cursor = GLUT_CURSOR_CROSSHAIR;
  }
}
Exemple #3
0
void LorentzCone::closest_point_separation(double const * p,
					double * coef) const {
  // compute point on boundry closest to given point
  double * sol = new double[size_]();
  find_closest_point(p, sol);
  if (type()==LORENTZ) {
    // cone is in canonical form
    for (int i=1; i<size_; ++i) {
      coef[i] = 2.0*sol[i];
    }
    coef[0] = -2.0*sol[0];
  }
  else if (type()==RLORENTZ) {
    coef[0] = -2.0*sol[1];
    coef[1] = -2.0*sol[0];
    for (int i=2; i<size_; ++i) {
      coef[i] = 2.0*sol[i];
    }
  }
  delete[] sol;
}
Exemple #4
0
Fichier : tcs3.c Projet : rc0/cstum
static void compute_distances(struct tower_table *table, struct tower_data *data)/*{{{*/
{
  int i, j;
  struct foo *board;
  board = malloc(table->n_towers * sizeof(struct foo));
  for (i=0; i<table->n_towers; i++) {
    struct tower2 *towi = table->towers[i];
    int X, Y;
    int n;
    printf("Tower %3d : (%s,%s) %s\n",
        i,
        towi->label_2g ?: "-",
        towi->label_3g ?: "-",
        towi->description);
    if (towi->has_observed) {
      X = towi->observed.X;
      Y = towi->observed.Y;
    } else if (towi->has_estimated) {
      X = towi->estimated.X;
      Y = towi->estimated.Y;
    } else {
      get_rough_tp_estimate(towi, &X, &Y);
    }
    X >>= (28 - THE_LEVEL);
    Y >>= (28 - THE_LEVEL);
    n = 0;
    for (j=0; j<table->n_towers; j++) {
      int d2, d3, d;
      if (j==i) continue;
      d2 = d3 = -1;
      if (data[i].c2.central && data[j].c2.central) {
        d2 = find_closest_point(data[j].c2.central, X, Y);
      }
      if (data[i].c3.central && data[j].c3.central) {
        d3 = find_closest_point(data[j].c3.central, X, Y);
      }
      if ((d2 >= 0) && (d3 >= 0)) {
        d = (d2 < d3) ? d2 : d3;
      } else if (d2 >= 0) {
        d = d2;
      } else if (d3 >= 0) {
        d = d3;
      } else {
        d = -1;
      }
      if (d >= 0) {
        board[n].d2 = d2;
        board[n].d3 = d3;
        board[n].d = d;
        board[n].i = j;
        n++;
      }
    }
    qsort(board, n, sizeof(struct foo), compare_foo);
    for (j=0; (j<20) && (j<n); j++) {
      struct tower2 *towj = table->towers[board[j].i];
      printf("    %8d  %8d  %8d   %3d : (%s,%s) %s\n",
          board[j].d,
          board[j].d2, board[j].d3,
          board[j].i,
          towj->label_2g ?: "-",
          towj->label_3g ?: "-",
          towj->description);
    }
  }
}
Exemple #5
0
int main (int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    std::vector<std::string> keywords;
    keywords.push_back("-ALL");
    keywords.push_back("-MESH");
    keywords.push_back("-LOWPASS");

    if (argc < 3)
    {
        INFO(
            "Moves mesh nodes and connected elements either by a given value "
            "or based on a list.\n");
        INFO("Usage: %s <msh-file.msh> <keyword> [<value1>] [<value2>]",
             argv[0]);
        INFO("Available keywords:");
        INFO(
            "\t-ALL <value1> <value2> : changes the elevation of all mesh "
            "nodes by <value2> in direction <value1> [x,y,z].");
        INFO(
            "\t-MESH <value1> <value2> : changes the elevation of mesh nodes "
            "based on a second mesh <value1> with a search range of <value2>.");
        INFO(
            "\t-LOWPASS : applies a lowpass filter over node elevation using "
            "directly connected nodes.");
        return EXIT_FAILURE;
    }

    const std::string msh_name(argv[1]);
    const std::string current_key(argv[2]);
    std::string const ext (BaseLib::getFileExtension(msh_name));
    if (!(ext == "msh" || ext == "vtu"))
    {
        ERR("Error: Parameter 1 must be a mesh-file (*.msh / *.vtu).");
        INFO("Usage: %s <msh-file.gml> <keyword> <value>", argv[0]);
        return EXIT_FAILURE;
    }

    bool is_keyword(false);
    for (auto & keyword : keywords)
        if (current_key.compare(keyword)==0)
        {
            is_keyword = true;
            break;
        }

    if (!is_keyword)
    {
        ERR("Keyword not recognised. Available keywords:");
        for (auto const& keyword : keywords)
            INFO("\t%s", keyword.c_str());
        return EXIT_FAILURE;
    }

    std::unique_ptr<MeshLib::Mesh> mesh (MeshLib::IO::readMeshFromFile(msh_name));
    if (mesh == nullptr)
    {
        ERR ("Error reading mesh file.");
        return 1;
    }

    // Start keyword-specific selection of nodes

    // moves the elevation of all nodes by value
    if (current_key.compare("-ALL")==0)
    {
        if (argc < 5)
        {
            ERR("Missing parameter...");
            return EXIT_FAILURE;
        }
        const std::string dir(argv[3]);
        unsigned idx = (dir.compare("x") == 0) ? 0 : (dir.compare("y") == 0) ? 1 : 2;
        const double value(strtod(argv[4],0));
        INFO("Moving all mesh nodes by %g in direction %d (%s)...", value, idx,
             dir.c_str());
        //double value(-10);
        const std::size_t nNodes(mesh->getNumberOfNodes());
        std::vector<MeshLib::Node*> nodes (mesh->getNodes());
        for (std::size_t i=0; i<nNodes; i++)
        {
            (*nodes[i])[idx] += value;
        }
    }

    // maps the elevation of mesh nodes according to a ground truth mesh whenever nodes exist within max_dist
    if (current_key.compare("-MESH")==0)
    {
        if (argc < 5)
        {
            ERR("Missing parameter...");
            return EXIT_FAILURE;
        }
        const std::string value (argv[3]);
        double max_dist(pow(strtod(argv[4],0), 2));
        double offset (0.0); // additional offset for elevation (should be 0)
        std::unique_ptr<MeshLib::Mesh> ground_truth (MeshLib::IO::readMeshFromFile(value));
        if (ground_truth == nullptr)
        {
            ERR ("Error reading mesh file.");
            return EXIT_FAILURE;
        }

        const std::vector<MeshLib::Node*>& ground_truth_nodes (ground_truth->getNodes());
        GeoLib::AABB bounding_box(ground_truth_nodes.begin(), ground_truth_nodes.end());
        MathLib::Point3d const& min(bounding_box.getMinPoint());
        MathLib::Point3d const& max(bounding_box.getMaxPoint());

        const std::size_t nNodes(mesh->getNumberOfNodes());
        std::vector<MeshLib::Node*> nodes (mesh->getNodes());

        for (std::size_t i=0; i<nNodes; i++)
        {
            bool is_inside (containsPoint(*nodes[i], min, max));
            if (is_inside)
            {
                int idx = find_closest_point(nodes[i], ground_truth_nodes, max_dist);
                if (idx>=0)
                    (*nodes[i])[2] = (*(ground_truth_nodes[idx]))[2]-offset;
            }
        }
    }

    // a simple lowpass filter for the elevation of mesh nodes using the elevation of each node
    // weighted by 2 and the elevation of each connected node weighted by 1
    if (current_key.compare("-LOWPASS")==0)
    {
        const std::size_t nNodes(mesh->getNumberOfNodes());
        std::vector<MeshLib::Node*> nodes (mesh->getNodes());

        std::vector<double> elevation(nNodes);
        for (std::size_t i=0; i<nNodes; i++)
            elevation[i] = (*nodes[i])[2];

        for (std::size_t i=0; i<nNodes; i++)
        {
            const std::vector<MeshLib::Node*> conn_nodes (nodes[i]->getConnectedNodes());
            const unsigned nConnNodes (conn_nodes.size());
            elevation[i] = (2*(*nodes[i])[2]);
            for (std::size_t j=0; j<nConnNodes; ++j)
                elevation[i] += (*conn_nodes[j])[2];
            elevation[i] /= (nConnNodes+2);
        }

        for (std::size_t i=0; i<nNodes; i++)
            (*nodes[i])[2] = elevation[i];
    }
    /**** add other keywords here ****/

    std::string const new_mesh_name (msh_name.substr(0, msh_name.length() - 4) + "_new.vtu");
    if (MeshLib::IO::writeMeshToFile(*mesh, new_mesh_name) != 0)
        return EXIT_FAILURE;

    INFO ("Result successfully written.")
    return EXIT_SUCCESS;
}