Esempio n. 1
0
	inline ActivityID *activity_id()
	{
		ActivityID *aid = new ActivityID;
		
		aid->id     = randr();
		aid->thread = randr();
		aid->cid    = *component_id();
		
		return aid;
	}
Esempio n. 2
0
    EdgeBasedNode()
        : forward_edge_based_node_id(SPECIAL_NODEID), reverse_edge_based_node_id(SPECIAL_NODEID),
          u(SPECIAL_NODEID), v(SPECIAL_NODEID), name_id(0),
          forward_weight(INVALID_EDGE_WEIGHT >> 1), reverse_weight(INVALID_EDGE_WEIGHT >> 1),
          forward_offset(0), reverse_offset(0), packed_geometry_id(SPECIAL_EDGEID),
          component_id(-1), fwd_segment_position(std::numeric_limits<unsigned short>::max()),
          forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
          backward_travel_mode(TRAVEL_MODE_INACCESSIBLE)
    {
    }

    explicit EdgeBasedNode(NodeID forward_edge_based_node_id,
                           NodeID reverse_edge_based_node_id,
                           NodeID u,
                           NodeID v,
                           unsigned name_id,
                           int forward_weight,
                           int reverse_weight,
                           int forward_offset,
                           int reverse_offset,
                           unsigned packed_geometry_id,
                           unsigned component_id,
                           unsigned short fwd_segment_position,
                           TravelMode forward_travel_mode,
                           TravelMode backward_travel_mode)
        : forward_edge_based_node_id(forward_edge_based_node_id),
          reverse_edge_based_node_id(reverse_edge_based_node_id), u(u), v(v), name_id(name_id),
          forward_weight(forward_weight), reverse_weight(reverse_weight),
          forward_offset(forward_offset), reverse_offset(reverse_offset),
          packed_geometry_id(packed_geometry_id), component_id(component_id),
          fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode),
          backward_travel_mode(backward_travel_mode)
    {
        BOOST_ASSERT((forward_edge_based_node_id != SPECIAL_NODEID) ||
                     (reverse_edge_based_node_id != SPECIAL_NODEID));
    }

    static inline FixedPointCoordinate Centroid(const FixedPointCoordinate &a,
                                                const FixedPointCoordinate &b)
    {
        FixedPointCoordinate centroid;
        // The coordinates of the midpoint are given by:
        centroid.lat = (a.lat + b.lat) / 2;
        centroid.lon = (a.lon + b.lon) / 2;
        return centroid;
    }
Esempio n. 3
0
const BaseMath &
BaseMath::writeStrongComponents( std::ostream & os ) const {

	typedef InputGraph Graph;
	auto const & g = this->_input_graph;

	Graph::NodeMap< int > component_id(g);
	const int n_components = stronglyConnectedComponents( g, component_id );

	std::vector< int > component_size( n_components, 0 );
	std::vector< int > component_non_dummy_size( n_components, 0 );

	/**
	 * Iterate all nodes, get the component id,
	 * update the size.
	 */
	for ( Graph::NodeIt n(g); n != lemon::INVALID; ++ n ) {
		++ component_size[ component_id[n] ];
		if ( !_dummy[n] ) {
			++ component_non_dummy_size[ component_id[n] ];
		}
	}

	os << "Strongly connected components of input graph = " << n_components << std::endl;
	os << "Component sizes =";
	for ( auto n : component_size ) {
		os << " " << n;
	}
	os << std::endl;

	os << "Component sizes (non-dummy) =";
	for ( auto n : component_non_dummy_size ) {
		os << " " << n;
	}
	os << std::endl;

	return *this;
}
Esempio n. 4
0
/**
 * Main function for cwb-makeall.
 *
 * @param argc   Number of command-line arguments.
 * @param argv   Command-line arguments.
 */
int
main(int argc, char **argv)
{
  char *attr_name = NULL;
  Attribute *attribute;

  char *registry_directory = NULL;
  char *corpus_id = NULL;

  extern int optind;
  extern char *optarg;
  int c;

  int validate = 0;

  char *component = NULL;

  ComponentID cid;
  int i = 0;

  /* ------------------------------------------------- PARSE ARGUMENTS */

  progname = argv[0];

  /* parse arguments */
  while ((c = getopt(argc, argv, "+r:c:P:hDM:V")) != EOF) {
    switch (c) {

    /* r: registry directory */
    case 'r':
      if (registry_directory == NULL)
        registry_directory = optarg;
      else {
        fprintf(stderr, "%s: -r option used twice\n", progname);
        exit(2);
      }
      break;

    case 'P':
      if (attr_name == NULL)
        attr_name = optarg;
      else {
        fprintf(stderr, "%s: -P option used twice\n", progname);
        exit(2);
      }
      break;

    case 'c':
      if (component == NULL)
        component = optarg;
      else {
        fprintf(stderr, "%s: -c option used twice\n", progname);
        exit(2);
      }
      break;

    case 'D':
      cl_set_debug_level(1);
      break;

    case 'M':
      i = atoi(optarg);
      cl_set_memory_limit(i);
      break;

    case 'V':
      validate++;
      break;

    case 'h':
    default:
      makeall_usage();
    }
  }

  if (optind >= argc) {
    fprintf(stderr, "Missing argument, try \"%s -h\" for more information.\n", progname);
    exit(1);
  }

  /* first argument: corpus id */
  corpus_id = argv[optind++];

  if (component != NULL) {
    cid = component_id(component);
    if (cid == CompLast) {
      fprintf(stderr, "Illegal component name: ``%s''\n", component);
      exit(1);
    }
  }
  else {
    cid = CompLast;
  }


  if ((corpus = cl_new_corpus(registry_directory, corpus_id)) == NULL) {
    fprintf(stderr, "Corpus %s not found in registry %s . Aborted.\n",
            corpus_id,
            (registry_directory ? registry_directory
             : central_corpus_directory()));
    exit(1);
  }

  printf("=== Makeall: processing corpus %s ===\n", corpus_id);
  printf("Registry directory: %s\n", corpus->registry_dir);

  if (optind < argc) {
    for (i = optind; i < argc; i++) {
      if ((attribute = cl_new_attribute(corpus, argv[i], ATT_POS)) != NULL) {
        makeall_do_attribute(attribute, cid, validate);
      }
      else {
        fprintf(stderr, "p-attribute %s.%s not defined. Aborted.\n",
                corpus_id, attr_name);
        exit(1);
      }
    }
  }
  else if (attr_name != NULL) {
    if ((attribute = cl_new_attribute(corpus, attr_name, ATT_POS)) != NULL) {
      makeall_do_attribute(attribute, cid, validate);
    }
    else {
      fprintf(stderr, "p-attribute %s.%s not defined. Aborted.\n",
              corpus_id, attr_name);
      exit(1);
    }
  }
  else {
    /* process each p-attribute of the corpus in turn */
    for (attribute = corpus->attributes; attribute; attribute = attribute->any.next)
      if (attribute->type == ATT_POS) {
        ComponentID my_cid;

        makeall_do_attribute(attribute, cid, validate);
        /* now destoy all components; this makes the attribute unusable,
           but it is currently the only way to free allocated and memory-mapped data */
        for (my_cid = CompDirectory; my_cid < CompLast; my_cid++) { /* ordering gleaned from attributes.h */
          drop_component(attribute, my_cid);
        }
      }
  }

  printf("========================================\n");
  exit(0);
}
Esempio n. 5
0
		explicit component(Component id) : id_(component_id(static_cast<unsigned long long>(id))) {}
Esempio n. 6
0
	inline component_id operator<<(int value, const Component& rhs) 
	{
		return component_id(value << static_cast<unsigned long long>(rhs));
	}
Esempio n. 7
0
		component_set(int z=0) : mask(component_id(0)), zorder(z) {}
// 传入的DOM模型为
// <SWComponent> 
// 	<Name>Tutor2-1</Name> 
// 	<SubComponents/> 
// 	<IsRoot>false</IsRoot> 
// 	<BoundingBox>
// 	<Bodies>
// 		<SWBody> 
// 			<Name>切除-拉伸1</Name>
// 			<Faces>
// 			<Edges>
// 			<Vertices>
// 		</SWBody> 
// 	</Bodies> 
//  <Mates />
// </SWComponent>
void ComponentInputDecorator::Parse(const char* id, xercesc::DOMElement* element) {
	//if (NULL == element || !vertices_.valid() || !normals_.valid() || NULL == component_parent_map_.get())
	//	return;

	if (NULL == id || NULL == element || NULL == component_parent_map_)
		return;

	char index[255];
	xercesc::DOMElement* current_element =NULL;
	xercesc::DOMNodeList* list = NULL;
	component_ = std::tr1::shared_ptr<vaar_data::Component>(new vaar_data::Component);

	// 解析Name
	std::string component_name;
	element = element->getFirstElementChild();

	if (NULL != element &&
		0 == strcmp("Name", xercesc::XMLString::transcode(element->getTagName()))) {
		component_name = xercesc::XMLString::transcode(element->getTextContent());

		component_->SetName(component_name.c_str());
	}

	// 生成ID
	std::string component_id(id);
	component_id += component_name;
	component_->SetID(component_id.c_str());

	// 解析SubComponents
	std::vector<vaar_data::Component*>* sub_components = new std::vector<vaar_data::Component*>();
	element = element->getNextElementSibling();
	if (NULL != element &&
		0 == strcmp("SubComponents", xercesc::XMLString::transcode(element->getTagName()))) {

		ComponentInputDecorator* component_input_decorator = NULL;
		int sub_component_index = 0;
		vaar_data::Component* sub_component = NULL;

		current_element = element->getFirstElementChild();
		do {
			if (NULL == current_element)
				break;

			// 分配SubComponent的ID
			std::string sub_component_id = component_id;
			
			_itoa_s(sub_component_index, index, 10);
			sub_component_id += "_sub";
			sub_component_id += index;
			++sub_component_index;

			//component_input_decorator = new ComponentInputDecorator(vertices_, normals_, component_parent_map_);
			component_input_decorator = new ComponentInputDecorator(component_parent_map_);
			component_input_decorator->Parse(sub_component_id.c_str(), current_element);
			sub_component = component_input_decorator->GetComponent();

			if (NULL != sub_component) {
				sub_components->push_back(sub_component);
				// 建立SubComponentID到Component的映射关系
				component_parent_map_->insert(
					std::pair<std::string, vaar_data::Component*>(sub_component_id, component_.get())
				);
			}
		} while (
			current_element != element->getLastElementChild(),
			current_element = current_element->getNextElementSibling()
		);
	}
	component_->SetSubComponents(sub_components);

	// 解析Faces
	std::vector<vaar_data::Face*>* faces = new std::vector<vaar_data::Face*>();
	element = element->getNextElementSibling();
	element = element->getNextElementSibling();
	element = element->getNextElementSibling();

	if (NULL != element &&
		0 == strcmp("Bodies", xercesc::XMLString::transcode(element->getTagName()))) {
		
		FaceInputDecorator* face_input_decorator = NULL;
		vaar_data::Face* face =NULL;

		list = element->getElementsByTagName(xercesc::XMLString::transcode("SWFace"));
		if (NULL != list) {
			for (XMLSize_t i = 0; i < list->getLength(); ++i) {
				current_element = dynamic_cast<xercesc::DOMElement*>(list->item(i));

				// 分配Face的ID
				std::string face_id = component_id;

				_itoa_s(i, index, 10);
				face_id += "_face";
				face_id += index;

				//face_input_decorator = new FaceInputDecorator();
				face_input_decorator = new FaceInputDecorator(
					component_->GetRefPtrTriangles(), 
					component_->GetRefPtrNormals()
				);
				face_input_decorator->Parse(face_id.c_str(), current_element);
				face = face_input_decorator->GetFace();

				if (NULL != face) {
					faces->push_back(face);
					// 建立SubFaceID到Component的映射关系
					component_parent_map_->insert(
						std::pair<std::string, vaar_data::Component*>(face_id, component_.get())
					);
				}
			}
		}
	}
	component_->SetFaces(faces);

	// 解析Edges
	std::vector<vaar_data::Edge*>* edges = new std::vector<vaar_data::Edge*>();
	EdgeInputDecorator* edge_input_decorator = NULL;
	vaar_data::Edge* edge = NULL;

	list = element->getElementsByTagName(xercesc::XMLString::transcode("SWEdge"));
	if (NULL != list) {
		for (XMLSize_t i = 0; i < list->getLength(); ++i) {
			current_element = dynamic_cast<xercesc::DOMElement*>(list->item(i));

			// 分配Edge的ID
			std::string edge_id = component_id;
			_itoa_s(i, index, 10);
			edge_id += "_edge";
			edge_id += index;

			edge_input_decorator = new EdgeInputDecorator();
			edge_input_decorator->Parse(edge_id.c_str(), current_element);
			edge = edge_input_decorator->GetEdge();

			if (NULL != edge) {
				edges->push_back(edge);
				// 建立SubEdgeID到Component的映射关系
				component_parent_map_->insert(
					std::pair<std::string, vaar_data::Component*>(edge_id, component_.get())
				);
			}
		}
	}
	component_->SetEdges(edges);

	// 解析Vertices
	std::vector<vaar_data::Vertex*>* vertices = new std::vector<vaar_data::Vertex*>();
	VertexInputDecorator* vertex_input_decorator = NULL;
	vaar_data::Vertex* vertex = NULL;

	list = element->getElementsByTagName(xercesc::XMLString::transcode("SWVertex"));
	if (NULL != list) {
		for (XMLSize_t i = 0; i < list->getLength(); ++i) {
			current_element = dynamic_cast<xercesc::DOMElement*>(list->item(i));

			// 分配Vertex的ID
			std::string vertex_id = component_id;
			_itoa_s(i, index, 10);
			vertex_id += "_vertex";
			vertex_id += index;

			vertex_input_decorator = new VertexInputDecorator();
			vertex_input_decorator->Parse(vertex_id.c_str(), current_element);
			vertex = vertex_input_decorator->GetVertex();

			if (NULL != vertex) {
				vertices->push_back(vertex);
				// 建立SubVertexID到Component的映射关系
				component_parent_map_->insert(
					std::pair<std::string, vaar_data::Component*>(vertex_id, component_.get())
				);
			}
		}
	}
	component_->SetVertices(vertices);

}