Пример #1
0
bool builder::resample_surfels(boost::filesystem::path const& input_file) const {
    std::cout << std::endl;
    std::cout << "--------------------------------" << std::endl;
    std::cout << "resample" << std::endl;
    std::cout << "--------------------------------" << std::endl;
    LOGGER_TRACE("resample stage");

    lamure::pre::bvh bvh(memory_limit_, desc_.buffer_size, desc_.rep_radius_algo);

    if (!bvh.load_tree(input_file.string())) {
        return false;
    }

    if (bvh.state() != bvh::state_type::after_downsweep) {
        LOGGER_ERROR("Wrong processing state!");
        return false;
    }

    CPU_TIMER;
    // perform resample
    bvh.resample();

    //write resampled leaf level out
    format_xyz format_out;
    std::unique_ptr<format_xyz> dummy_format_in{new format_xyz()};
    auto xyz_res_file = add_to_path(base_path_, "_res.xyz");
    converter conv(*dummy_format_in, format_out, desc_.buffer_size);
    surfel_vector resampled_ll = bvh.get_resampled_leaf_lv_surfels();
    conv.write_in_core_surfels_out(resampled_ll, xyz_res_file.string());
    
    std::remove(input_file.string().c_str());

// LOGGER_DEBUG("Used memory: " << GetProcessUsedMemory() / 1024 / 1024 << " MiB");
    return true;
}
Пример #2
0
void vc_iterate(VCSession *vc)
{
    if (!vc) {
        return;
    }

    pthread_mutex_lock(vc->queue_mutex);

    struct RTPMessage *p;

    if (!rb_read(vc->vbuf_raw, (void **)&p)) {
        LOGGER_TRACE(vc->log, "no Video frame data available");
        pthread_mutex_unlock(vc->queue_mutex);
        return;
    }

    pthread_mutex_unlock(vc->queue_mutex);
    const struct RTPHeader *const header = &p->header;

    uint32_t full_data_len;

    if (header->flags & RTP_LARGE_FRAME) {
        full_data_len = header->data_length_full;
        LOGGER_DEBUG(vc->log, "vc_iterate:001:full_data_len=%d", (int)full_data_len);
    } else {
        full_data_len = p->len;
        LOGGER_DEBUG(vc->log, "vc_iterate:002");
    }

    LOGGER_DEBUG(vc->log, "vc_iterate: rb_read p->len=%d p->header.xe=%d", (int)full_data_len, p->header.xe);
    LOGGER_DEBUG(vc->log, "vc_iterate: rb_read rb size=%d", (int)rb_size(vc->vbuf_raw));
    const vpx_codec_err_t rc = vpx_codec_decode(vc->decoder, p->data, full_data_len, nullptr, MAX_DECODE_TIME_US);
    free(p);

    if (rc != VPX_CODEC_OK) {
        LOGGER_ERROR(vc->log, "Error decoding video: %d %s", (int)rc, vpx_codec_err_to_string(rc));
        return;
    }

    /* Play decoded images */
    vpx_codec_iter_t iter = nullptr;

    for (vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter);
            dest != nullptr;
            dest = vpx_codec_get_frame(vc->decoder, &iter)) {
        if (vc->vcb) {
            vc->vcb(vc->av, vc->friend_number, dest->d_w, dest->d_h,
                    (const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2],
                    dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb_user_data);
        }

        vpx_img_free(dest); // is this needed? none of the VPx examples show that
    }
}
Пример #3
0
    void InitialiseBasics (int argv, char* argc[]) {
      TRIAGENS_C_INITIALISE(argv, argc);

      // use the rng so the linker does not remove it from the executable
      // we might need it later because .so files might refer to the symbols
      Random::random_e v = Random::selectVersion(Random::RAND_MERSENNE);
      Random::UniformInteger random(0, 1);
      random.random();
      Random::selectVersion(v);

      string revision = "$Revision: BASICS " TRIAGENS_VERSION " (c) triAGENS GmbH $";
      LOGGER_TRACE(revision);

#ifdef TRI_BROKEN_CXA_GUARD
      pthread_cond_t cond;
      pthread_cond_init(&cond, 0);
      pthread_cond_broadcast(&cond);
#endif
    }
Пример #4
0
void format_bin::
write(const std::string& filename, buffer_callback_function callback)
{

    file file;
    surfel_vector buffer;
    size_t count = 0;

    file.open(filename, true);
    while (true) {
        bool ret = callback(buffer);
        if (!ret)
            break;

        file.append(&buffer);
        count += buffer.size();
    }
    file.close();
    LOGGER_TRACE("Output surfels: " << count);
}
Пример #5
0
boost::filesystem::path builder::upsweep(boost::filesystem::path input_file,
                     uint16_t start_stage,
                     reduction_strategy const* reduction_strategy,
                     normal_computation_strategy const* normal_comp_strategy,
                     radius_computation_strategy const* radius_comp_strategy) const {
    std::cout << std::endl;
    std::cout << "--------------------------------" << std::endl;
    std::cout << "upsweep" << std::endl;
    std::cout << "--------------------------------" << std::endl;
    LOGGER_TRACE("upsweep stage");

    lamure::pre::bvh bvh(memory_limit_, desc_.buffer_size, desc_.rep_radius_algo);

    if (!bvh.load_tree(input_file.string())) {
        return boost::filesystem::path{};
    }

    if (bvh.state() != bvh::state_type::after_downsweep) {
        LOGGER_ERROR("Wrong processing state!");
        return boost::filesystem::path{};
    }

    CPU_TIMER;
    // perform upsweep
    bvh.upsweep(*reduction_strategy, 
                *normal_comp_strategy, 
                *radius_comp_strategy,
                desc_.compute_normals_and_radii,
                desc_.resample);

    auto bvhu_file = add_to_path(base_path_, ".bvhu");
    bvh.serialize_tree_to_file(bvhu_file.string(), true);

    if ((!desc_.keep_intermediate_files) && (start_stage < 2)) {
        std::remove(input_file.string().c_str());
    }

    input_file = bvhu_file;
// LOGGER_DEBUG("Used memory: " << GetProcessUsedMemory() / 1024 / 1024 << " MiB");
    return input_file;
}
Пример #6
0
boost::filesystem::path builder::convert_to_binary(std::string const& input_type) const{
    std::cout << std::endl;
    std::cout << "--------------------------------" << std::endl;
    std::cout << "convert input file" << std::endl;
    std::cout << "--------------------------------" << std::endl;

    LOGGER_TRACE("convert to a binary file");
    auto input_file = fs::canonical(fs::path(desc_.input_file));
    std::shared_ptr<format_abstract> format_in{};
    auto binary_file = base_path_;

    if (input_type == ".xyz") {
        binary_file += ".bin";
        format_in = std::unique_ptr<format_xyz>{new format_xyz()};
    }
    else if (input_type == ".xyz_all") {
        binary_file += ".bin_all";
        format_in = std::unique_ptr<format_xyzall>{new format_xyzall()};
    }
    else if (input_type == ".ply") {
        binary_file += ".bin";
        format_in = std::unique_ptr<format_ply>{new format_ply()};
    }
    else {
        LOGGER_ERROR("Unable to convert input file: Unknown file format");
        return boost::filesystem::path{};
    }

    format_bin format_out;

    converter conv(*format_in, format_out, desc_.buffer_size);

    conv.set_surfel_callback([](surfel &s, bool& keep) { if (s.pos() == vec3r(0.0,0.0,0.0)) keep = false; });
    //conv.set_scale_factor(1);
    //conv.set_translation(vec3r(-605535.577, -5097551.573, -1468.071));

    CPU_TIMER;
    conv.convert(input_file.string(), binary_file.string());
    // LOGGER_DEBUG("Used memory: " << GetProcessUsedMemory() / 1024 / 1024 << " MiB");
    return binary_file;
}
Пример #7
0
      void fillBuffer () {
        size_t n = sizeof(buffer);
        char* ptr = reinterpret_cast<char*>(&buffer);

        while (0 < n) {
          ssize_t r = TRI_READ(fd, ptr, n);

          if (r == 0) {
            LOGGER_FATAL_AND_EXIT("read on random device failed: nothing read");
          }
          else if (errno == EWOULDBLOCK) {
            LOGGER_INFO("not enough entropy (got " << (sizeof(buffer) - n) << " bytes), switching to pseudo-random");
            break;
          }
          else if (r < 0) {
            LOGGER_FATAL_AND_EXIT("read on random device failed: " << strerror(errno));
          }

          ptr += r;
          n -= r;

          rseed = buffer[0];

          LOGGER_TRACE("using seed " << rseed);
        }

        if (0 < n) {
          unsigned long seed = RandomDevice::getSeed();
          TRI_SeedMersenneTwister((uint32_t) (rseed ^ (uint32_t) seed));

          while (0 < n) {
            *ptr++ = TRI_Int32MersenneTwister();
            --n;
          }
        }

        pos = 0;
      }
Пример #8
0
boost::filesystem::path builder::downsweep(boost::filesystem::path input_file, uint16_t start_stage) const{
    bool performed_outlier_removal = false;
    do {
        std::string status_suffix = "";
        if ( true == performed_outlier_removal ) {
            status_suffix = " (after outlier removal)";
        }

        std::cout << std::endl;
        std::cout << "--------------------------------" << std::endl;
        std::cout << "bvh properties" << status_suffix << std::endl;
        std::cout << "--------------------------------" << std::endl;

        lamure::pre::bvh bvh(memory_limit_, desc_.buffer_size, desc_.rep_radius_algo);

        bvh.init_tree(input_file.string(),
                          desc_.max_fan_factor,
                          desc_.surfels_per_node,
                          base_path_);

        bvh.print_tree_properties();
        std::cout << std::endl;

        std::cout << "--------------------------------" << std::endl;
        std::cout << "downsweep" << status_suffix << std::endl;
        std::cout << "--------------------------------" << std::endl;
        LOGGER_TRACE("downsweep stage");

        CPU_TIMER;
        bvh.downsweep(desc_.translate_to_origin, input_file.string());

        auto bvhd_file = add_to_path(base_path_, ".bvhd");

        bvh.serialize_tree_to_file(bvhd_file.string(), true);

        if ((!desc_.keep_intermediate_files) && (start_stage < 1))
        {
            // do not remove input file
            std::remove(input_file.string().c_str());
        }

        input_file = bvhd_file;

        // LOGGER_DEBUG("Used memory: " << GetProcessUsedMemory() / 1024 / 1024 << " MiB");

        if ( 3 <= start_stage ) {
            break;
        }

        if ( performed_outlier_removal ) {
            break;
        }

        if(start_stage <= 2 ) {

            if(desc_.outlier_ratio != 0.0) {

                size_t num_outliers = desc_.outlier_ratio * (bvh.nodes().size() - bvh.first_leaf()) * bvh.max_surfels_per_node();
                size_t ten_percent_of_surfels = std::max( size_t(0.1 * (bvh.nodes().size() - bvh.first_leaf()) * bvh.max_surfels_per_node()), size_t(1) );
                num_outliers = std::min(std::max(num_outliers, size_t(1) ), ten_percent_of_surfels); // remove at least 1 surfel, for any given ratio != 0.0


                std::cout << std::endl;
                std::cout << "--------------------------------" << std::endl;
                std::cout << "outlier removal ( " << int(desc_.outlier_ratio * 100) << " percent = " << num_outliers << " surfels)" << std::endl;
                std::cout << "--------------------------------" << std::endl;
                LOGGER_TRACE("outlier removal stage");

                surfel_vector kept_surfels = bvh.remove_outliers_statistically(num_outliers, desc_.number_of_outlier_neighbours);

                format_bin format_out;

                std::unique_ptr<format_abstract> dummy_format_in{new format_xyz()};

                converter conv(*dummy_format_in, format_out, desc_.buffer_size);

                conv.set_surfel_callback([](surfel &s, bool& keep) { if (s.pos() == vec3r(0.0,0.0,0.0)) keep = false; });

                auto binary_outlier_removed_file = add_to_path(base_path_, ".bin_wo_outlier");

                conv.write_in_core_surfels_out(kept_surfels, binary_outlier_removed_file.string());

                bvh.reset_nodes();

                input_file = fs::canonical(binary_outlier_removed_file);

                performed_outlier_removal = true;
            } else {
                break;
            }

        }

    } while( true );

    return input_file;
}
Пример #9
0
    void SimpleHttpClient::setRequest (rest::HttpRequest::HttpRequestType method,
            const string& location,
            const char* body,
            size_t bodyLength,
            const map<string, string>& headerFields) {

      if (_state == DEAD) {
        _connection->resetNumConnectRetries();
      }

      ///////////////////// fill the write buffer //////////////////////////////      
      _writeBuffer.clear();

      HttpRequest::appendMethod(method, &_writeBuffer);

      string l = location;
      if (location.length() == 0 || location[0] != '/') {
        l = "/" + location;
      }

      _writeBuffer.appendText(l);
      _writeBuffer.appendText(" HTTP/1.1\r\n");

      _writeBuffer.appendText("Host: ");
      _writeBuffer.appendText(_connection->getEndpoint()->getHostString());
      _writeBuffer.appendText("\r\n");
      _writeBuffer.appendText("Connection: Keep-Alive\r\n");
      _writeBuffer.appendText("User-Agent: VOC-Client/1.0\r\n");

      // do basic authorization
      if (! _pathToBasicAuth.empty()) {
        string foundPrefix;
        string foundValue;
        std::vector< std::pair<std::string, std::string> >::iterator i = _pathToBasicAuth.begin();
        for (; i != _pathToBasicAuth.end(); ++i) {
          string f = i->first;
          if (l.find(f) == 0) {
            // f is prefix of l
            if (f.length() > foundPrefix.length()) {
              foundPrefix = f;
              foundValue = i->second;
            }
          }
        }
        if (foundValue.length() > 0) {
          _writeBuffer.appendText("Authorization: Basic ");
          _writeBuffer.appendText(foundValue);
          _writeBuffer.appendText("\r\n");
        }
      }

      for (map<string, string>::const_iterator i = headerFields.begin(); i != headerFields.end(); ++i) {
        // TODO: check Header name and value
        _writeBuffer.appendText(i->first);
        _writeBuffer.appendText(": ");
        _writeBuffer.appendText(i->second);
        _writeBuffer.appendText("\r\n");
      }

      _writeBuffer.appendText("Content-Length: ");
      _writeBuffer.appendInteger(bodyLength);
      _writeBuffer.appendText("\r\n\r\n");
      _writeBuffer.appendText(body, bodyLength);

      LOGGER_TRACE("Request: " << _writeBuffer.c_str());

      //////////////////////////////////////////////////////////////////////////


      if (_state != FINISHED) {
        // close connection to reset all read and write buffers
        this->close();
      }

      if (_connection->isConnected()) {
        // we are connected, start with writing
        _state = IN_WRITE;
        _written = 0;
      }
      else {
        // connect to server
        _state = IN_CONNECT;
      }
    }
Пример #10
0
void Provider_System::init(Handle<std::string> folder){
#if defined(OPENSSL_SYS_UNIX) 
	DIR *dir;
	class dirent *ent;
	class stat st;
	BIO *bioFile;

	if((dir = opendir(folder->c_str())) == NULL){
		if (mkdir(folder->c_str(), 0700) != 0){
			THROW_EXCEPTION(0, Provider_System, NULL, "Error create folder");
		}
	}
	else{
		closedir(dir);
	}

	std::string listCertStore[] = {
		"MY",
		"OTHERS",
		"TRUST",
		"CRL"
	};

	for (int i = 0, c = sizeof(listCertStore) / sizeof(*listCertStore); i < c; i++){
		std::string dirInCertStore = (std::string)folder->c_str() + CROSSPLATFORM_SLASH + listCertStore[i].c_str();
		dir = opendir(dirInCertStore.c_str());
		if(dir == NULL){
			if (mkdir(dirInCertStore.c_str(), 0700) != 0){
				THROW_EXCEPTION(0, Provider_System, NULL, "Error create folder");
			}

			continue;
		}
		while ((ent = readdir(dir)) != NULL) {
			const std::string file_name = ent->d_name;
			const std::string uri = dirInCertStore + CROSSPLATFORM_SLASH +   file_name;

			if (file_name[0] == '.')
				continue;

			const bool is_directory = (stat(uri.c_str(), &st) == 0) && S_ISDIR(st.st_mode);

			if (is_directory)
				continue;

			LOGGER_OPENSSL(BIO_new);
			bioFile = BIO_new(BIO_s_file());
			LOGGER_OPENSSL(BIO_read_filename);
			if (BIO_read_filename(bioFile, uri.c_str()) > 0){
				Handle<PkiItem> itemTemp = new PkiItem();
				itemTemp = objectToPKIItem(new std::string(uri));
				if (!itemTemp.isEmpty()){
					providerItemCollection->push(itemTemp);
				}	
			}
			LOGGER_OPENSSL(BIO_free);
			BIO_free(bioFile);
		}
		closedir(dir);
	}
#endif
#if defined(OPENSSL_SYS_WINDOWS) 
	LOGGER_FN();

	try{
		HANDLE dir;
		WIN32_FIND_DATA file_data;
		TCHAR szDir[MAX_PATH];
		BIO *bioFile;

		if ((dir = FindFirstFile(folder->c_str(), &file_data)) == INVALID_HANDLE_VALUE){
			if (_mkdir(folder->c_str()) != 0){
				THROW_EXCEPTION(0, Provider_System, NULL, "Error create folder");
			}
		}

		std::string listCertStore[] = {
			"MY",
			"OTHERS",
			"TRUST",
			"CRL"
		};

		for (int i = 0, c = sizeof(listCertStore) / sizeof(*listCertStore); i < c; i++){
			std::string dirInCertStore = (std::string)folder->c_str() + CROSSPLATFORM_SLASH + listCertStore[i].c_str();
			std::string tempdirInCertStore = "";
			tempdirInCertStore = dirInCertStore + "\\*";
			LOGGER_TRACE("FindFirstFile");
			if ((dir = FindFirstFile(tempdirInCertStore.c_str(), &file_data)) == INVALID_HANDLE_VALUE){			
				if (_mkdir(dirInCertStore.c_str()) != 0){
					THROW_EXCEPTION(0, Provider_System, NULL, "Error create folder");
				}

				continue;
			}

			do {
				std::string str = file_data.cFileName;
				std::wstring file_name(str.begin(), str.end());
				std::string uri = dirInCertStore + CROSSPLATFORM_SLASH + std::string(file_name.begin(), file_name.end());
				const bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;

				if (file_name[0] == '.')
					continue;

				if (is_directory)
					continue;

				LOGGER_OPENSSL(BIO_new);
				bioFile = BIO_new(BIO_s_file());
				LOGGER_OPENSSL(BIO_read_filename);
				if (BIO_read_filename(bioFile, uri.c_str()) > 0){
					Handle<PkiItem> itemTemp = new PkiItem();
					itemTemp = objectToPKIItem(new std::string(uri));
					if (!itemTemp.isEmpty()){
						providerItemCollection->push(itemTemp);
					}					
				}
			
			//	LOGGER_OPENSSL(BIO_free);
			//	BIO_free_all(bioFile);

			} while (FindNextFile(dir, &file_data));

			FindClose(dir);
		}
	}
	catch (Handle<Exception> e){
		THROW_EXCEPTION(0, Provider_System, e, "Error init system store");
	}

#endif
}