Beispiel #1
0
PixelBuf GradientMap::GetRegion(
        const MapPixelCoordInt &pos, const MapPixelDeltaInt &size) const
{
    auto fixed_bounds_pb = GetRegion_BoundsHelper(*this, pos, size);
    if (fixed_bounds_pb.GetData())
        return fixed_bounds_pb;

    //time_counter_loaddisc.Start();
    MapPixelCoordInt req_pos = pos - MapPixelDeltaInt(1, 1);
    MapPixelDeltaInt req_size = size + MapPixelDeltaInt(2, 2);
    auto orig_data = m_orig_map->GetRegion(req_pos, req_size);
    //auto orig_data = LoadBufferFromBMP(L"example.bmp");
    PixelBuf result(size.x, size.y);

    unsigned int *src = orig_data.GetRawData();
    unsigned int *dest = result.GetRawData();
    //time_counter_loaddisc.Stop();
    //time_counter.Start();
    for (int x=0; x < size.x; x++) {
        for (int y=0; y < size.y; y++) {
            unsigned int elevation = SRC(x+1, y+1);
            MapPixelCoordInt pos(x+1, y+1);
            MapBezierGradient grad = Fast3x3CenterGradient(src, pos, req_size);

            DEST(x, y) = HSV_to_RGB(
                      255*240/360 - elevation*255/4000,
                      255,
                      ValueBetween(0,
                                   static_cast<int>(128+1.25*(grad.x-grad.y)),
                                   255));
        }
    }
    //time_counter.Stop();
    return result;
}
Beispiel #2
0
//_____________________________________
void KVINDRAReconIdent::EndRun(void)
{
   //At the end of each run we:
   //      write the tree into the new file
   //      close the file
   //      copy the file into the required repository (see InitRun)
   //      update the available runlist

   fIdentFile->cd();

	gDataAnalyser->WriteBatchInfo(fIdentTree);

    GetRawData()->CloneTree(-1,"fast"); //copy raw data tree to file
    GetGeneData()->CloneTree(-1,"fast"); //copy pulser & laser (gene) tree to file

    fIdentFile->Write();

   //add file to repository
   // get dataset to which we must associate new run
   KVDataSet* OutputDataset =
      gDataRepositoryManager->GetDataSet(
         gDataSet->GetDataSetEnv("ReconIdent.DataAnalysisTask.OutputRepository", gDataRepository->GetName()),
         gDataSet->GetName() );

   OutputDataset->CommitRunfile("ident", gIndra->GetCurrentRunNumber(),
                           fIdentFile);
   fIdentFile = 0;
   fIdentTree = 0;
}
Beispiel #3
0
PixelBuf SteepnessMap::GetRegion(
        const MapPixelCoordInt &pos, const MapPixelDeltaInt &size) const
{
    auto fixed_bounds_pb = GetRegion_BoundsHelper(*this, pos, size);
    if (fixed_bounds_pb.GetData())
        return fixed_bounds_pb;

    double mpp;
    if (!MetersPerPixel(m_orig_map, pos + size/2, &mpp)) {
        // Return zero-initialized memory block.
        return PixelBuf(size.x, size.y);
    }
    unsigned int bezier_pixels = Bezier::N_POINTS - 1;
    double inv_bezier_meters = 1 / (bezier_pixels * mpp);

    MapPixelCoordInt req_pos = pos - MapPixelDeltaInt(1, 1);
    MapPixelDeltaInt req_size = size + MapPixelDeltaInt(2, 2);
    auto orig_data = m_orig_map->GetRegion(req_pos, req_size);
    PixelBuf result(size.x, size.y);

    unsigned int *src = orig_data.GetRawData();
    unsigned int *dest = result.GetRawData();
    for (int x=0; x < size.x; x++) {
        for (int y=0; y < size.y; y++) {
            MapPixelCoordInt pos(x+1, y+1);
            MapBezierGradient grad = Fast3x3CenterGradient(src, pos, req_size);
            grad *= inv_bezier_meters;
            double grad_steepness = atan(grad.Abs());
            int color_index = static_cast<int>(grad_steepness / (M_PI / 2) * 18);
            DEST(x, y) = steepness_colors[color_index];
        }
    }
    return result;
}
float Geometry::GetHitDistance(const Ray& ray, Vector3* outNormal, Vector2* outUV) const
{
    const unsigned char* vertexData;
    const unsigned char* indexData;
    unsigned vertexSize;
    unsigned indexSize;
    const PODVector<VertexElement>* elements;

    GetRawData(vertexData, vertexSize, indexData, indexSize, elements);
    
    if (!vertexData || !elements || VertexBuffer::GetElementOffset(*elements, TYPE_VECTOR3, SEM_POSITION) != 0)
        return M_INFINITY;

    unsigned uvOffset = VertexBuffer::GetElementOffset(*elements, TYPE_VECTOR2, SEM_TEXCOORD);
    
    if (outUV && uvOffset == M_MAX_UNSIGNED)
    {
        // requested UV output, but no texture data in vertex buffer
        ATOMIC_LOGWARNING("Illegal GetHitDistance call: UV return requested on vertex buffer without UV coords");
        *outUV = Vector2::ZERO;
        outUV = 0;
    }

    return indexData ? ray.HitDistance(vertexData, vertexSize, indexData, indexSize, indexStart_, indexCount_, outNormal, outUV,
        uvOffset) : ray.HitDistance(vertexData, vertexSize, vertexStart_, vertexCount_, outNormal, outUV, uvOffset);
}
Beispiel #5
0
/*--------------------------------------------------------------------------*/
int sciReturnUserData(void* _pvCtx, const int * userData, int userDataSize)
{
  int * data_ptr = NULL ;
  int data_size = (userDataSize + 1) / 2 ;
  SetWorkSize(Rhs+1,&data_size);
  data_ptr = GetRawData(Rhs+1);
  memcpy(data_ptr, userData, userDataSize * sizeof (int));
  return 0 ;
}
VError AXMLDocument::WriteToStream( VStream *pStream,sLONG pParam ) const
{
	VString	XmlText;
	GetRawData( XmlText, true);

	VStringConvertBuffer buffer( XmlText, VTextConverters::Get()->GetCharSetFromName( fEncoding));
	VError result = pStream->PutData( buffer.GetCPointer(), buffer.GetSize());

	return result;

}
bool FExrImageWrapper::GetRaw( const ERGBFormat::Type InFormat, int32 InBitDepth, const TArray<uint8>*& OutRawData )
{
	LastError.Empty();
	Uncompress(InFormat, InBitDepth);

	if (LastError.IsEmpty())
	{
		OutRawData = &GetRawData();
	}

	return LastError.IsEmpty();
}
Beispiel #8
0
void CUpdater::ProcessNotification(std::unique_ptr<CNotification> && notification)
{
	if (state_ != UpdaterState::checking && state_ != UpdaterState::newversion_downloading) {
		return;
	}

	switch (notification->GetID())
	{
	case nId_asyncrequest:
		{
			auto pData = unique_static_cast<CAsyncRequestNotification>(std::move(notification));
			if (pData->GetRequestID() == reqId_fileexists) {
				static_cast<CFileExistsNotification *>(pData.get())->overwriteAction = CFileExistsNotification::resume;
			}
			else if (pData->GetRequestID() == reqId_certificate) {
				auto & certNotification = static_cast<CCertificateNotification &>(*pData.get());
				if (m_use_internal_rootcert) {
					auto certs = certNotification.GetCertificates();
					if( certs.size() > 1 ) {
						auto ca = certs.back();

						unsigned int ca_data_length{};
						unsigned char const* ca_data = ca.GetRawData(ca_data_length);

						wxMemoryBuffer updater_root = wxBase64Decode(s_update_cert, wxNO_LEN, wxBase64DecodeMode_SkipWS);
						if( ca_data_length == updater_root.GetDataLen() && !memcmp(ca_data, updater_root.GetData(), ca_data_length) ) {
							certNotification.m_trusted = true;
						}
					}
				}
				else {
					certNotification.m_trusted = true;
				}
			}
			engine_->SetAsyncRequestReply(std::move(pData));
		}
		break;
	case nId_data:
		ProcessData(static_cast<CDataNotification&>(*notification.get()));
		break;
	case nId_operation:
		ProcessOperation(static_cast<COperationNotification const&>(*notification.get()));
		break;
	case nId_logmsg:
		{
			auto const& msg = static_cast<CLogmsgNotification const&>(*notification.get());
			log_ += msg.msg + _T("\n");
		}
		break;
	default:
		break;
	}
}
bool Geometry::IsInside(const Ray& ray) const
{
    const unsigned char* vertexData;
    const unsigned char* indexData;
    unsigned vertexSize;
    unsigned indexSize;
    const PODVector<VertexElement>* elements;

    GetRawData(vertexData, vertexSize, indexData, indexSize, elements);

    return vertexData ? (indexData ? ray.InsideGeometry(vertexData, vertexSize, indexData, indexSize, indexStart_, indexCount_) :
                         ray.InsideGeometry(vertexData, vertexSize, vertexStart_, vertexCount_)) : false;
}
Beispiel #10
0
bool Geometry::IsInside(const Ray& ray) const
{
    const unsigned char* vertexData;
    const unsigned char* indexData;
    unsigned vertexSize;
    unsigned indexSize;
    unsigned elementMask;
    
    GetRawData(vertexData, vertexSize, indexData, indexSize, elementMask);
    
    if (vertexData && indexData)
        return ray.InsideGeometry(vertexData, vertexSize, indexData, indexSize, indexStart_, indexCount_);
    else if (vertexData)
        return ray.InsideGeometry(vertexData, vertexSize, vertexStart_, vertexCount_);
    else
        return false;
}
Beispiel #11
0
float Geometry::GetHitDistance(const Ray& ray, Vector3* outNormal) const
{
    const unsigned char* vertexData;
    const unsigned char* indexData;
    unsigned vertexSize;
    unsigned indexSize;
    unsigned elementMask;
    
    GetRawData(vertexData, vertexSize, indexData, indexSize, elementMask);
    
    if (vertexData && indexData)
        return ray.HitDistance(vertexData, vertexSize, indexData, indexSize, indexStart_, indexCount_, outNormal);
    else if (vertexData)
        return ray.HitDistance(vertexData, vertexSize, vertexStart_, vertexCount_, outNormal);
    else
        return M_INFINITY;
}
VError AXMLDocument::WriteToHandle( VHandle *pHandle,sLONG pParam) const
{
	VString	XmlText;
	GetRawData( XmlText, true);
	
	VStringConvertBuffer buffer( XmlText, VTextConverters::Get()->GetCharSetFromName( fEncoding));

//	sLONG	inMaxDestBytes = XmlText.GetSpace();

	if (VMemory::SetHandleSize( *pHandle, buffer.GetSize()) == VE_OK)
	{
		void *inDestination = VMemory::LockHandle( *pHandle);
		::memmove( inDestination, buffer.GetCPointer(), buffer.GetSize());
		VMemory::UnlockHandle( *pHandle);
	}

	return VE_OK;
}
Beispiel #13
0
PixelBuf decompress_jpeg(const std::string &buf, bool swap_rb) {
    jpeg_decompress_struct cinfo;
    jpeg_error_mgr err_mgr;

    // Set up the normal JPEG error routines, then override error_exit.
    cinfo.err = jpeg_std_error(&err_mgr);
    err_mgr.error_exit = error_exit_handler;

    // Attach an unique_ptr directly after creation, to ensure
    // jpeg_destroy_decompress() is called in case an exception occurrs.
    jpeg_create_decompress(&cinfo);
    auto deleter = [](j_decompress_ptr p){ jpeg_destroy_decompress(p); };
    std::unique_ptr<jpeg_decompress_struct, decltype(deleter)>
            cleanup_cinfo(&cinfo, deleter);

    jpeg_mem_src(&cinfo, (JOCTET*)buf.c_str(), buf.size());
    jpeg_read_header(&cinfo, /* require_image = */ true);

    // Ensure we get 24 bit RGB or an error, without explicitly setting the
    // out_color_space, we might get grayscale or CMYK data.
    // Libjpeg can do the color conversions if necessary.
    cinfo.out_color_space = JCS_RGB;
    jpeg_start_decompress(&cinfo);

    if (cinfo.output_components != 3) {
        // This should never happen, as we explicitly set JCS_RGB and libjpeg
        // should honor it. We might get a nasty buffer overflow if it doesn't,
        // so guard against it.
        throw JPEGError("Invalid number of JPEG color components.");
    }
    int row_stride = cinfo.output_width * cinfo.output_components;
    auto output = PixelBuf(cinfo.output_width, cinfo.output_height);
    auto output_buf = reinterpret_cast<unsigned char*>(output.GetRawData());

    // PixelBuf works on 32-bit RGBX values, while libjpeg can only provide 24
    // bit packed RGB. Read that into the PixelBuf buffer first, then space it
    // out in a second step later.
    JSAMPROW rows[1];
    bool top_down = false;
    unsigned int pos = top_down ? 0 : row_stride * (cinfo.output_height - 1);
    int pos_delta = top_down ? row_stride : -row_stride;
    unsigned int pos_end = pos + cinfo.output_height * pos_delta;
    while (cinfo.output_scanline < cinfo.output_height && pos != pos_end) {
        // TODO: Use a larger output JSAMPARRAY and handle return value of
        // jpeg_read_scanlines(). Cf. cinfo.rec_outbuf_height
        rows[0] = &output_buf[pos];
        (void) jpeg_read_scanlines(&cinfo, rows, 1);
        pos += pos_delta;
    }

    jpeg_finish_decompress(&cinfo);

    // Convert 24 bit RGB to 32 bit RGBX, possibly exchange R and B channels.
    int R = swap_rb ? 2 : 0;
    int G = 1;
    int B = swap_rb ? 0 : 2;
    unsigned int num_pixels = output.GetWidth() * output.GetHeight();
    for (int i = num_pixels - 1; i >= 0; i--) {
        unsigned int val = (output_buf[3*i + R] << 0) |
                           (output_buf[3*i + G] << 8) |
                           (output_buf[3*i + B] << 16);
        *reinterpret_cast<unsigned int*>(&output_buf[4*i]) = val;
    }
    return output;
}
		bool AgilentRawData::GetRawData(std::vector <double>	*mzs, std::vector<double> *intensities, int scan_num) 
		{
			return GetRawData(mzs, intensities,	scan_num, -1) ;	
		}
Beispiel #15
0
DWORD WINAPI reading_thread(void *param) {
    static const int ABM_SAMPLELENGTH = 4;					// approximate duration of one sample in ms
    static const int ABM_TP_PACKAGESIZE = 12;				// number of bytes in one package of thirdparty data
    static const int ABM_TP_TIME_OFFSET = 3;				// offset (in bytes) of where the third party timestamp starts
    static const int ABM_TP_DATA_OFFSET = 10;				// offset (in bytes) of where the third party data starts
    static const int ABM_TIME_PACKAGESIZE = 4;				// number of bytes in one timestamp package
    static const int ABM_RAW_PACKAGESIZE = 16;				// number of bytes in one raw data package
    static const int ABM_RAW_CHANNEL1_OFFSET = 6;			// offset (in bytes) until channel 1 starts

    std::deque<float> raw_data;								// raw data as received
    std::deque<unsigned int> raw_data_ts;					// timestamps for the raw data (ms)
    std::deque<unsigned char> events;						// events as received
    std::deque<unsigned int> events_ts;						// timestamps for the events (ms)
    unsigned char latest_event = 0;							//

    while (running) {
        {
            concurrency::critical_section::scoped_lock lock(bci_mutex);
            int rawCount, thirdPartySize;
            unsigned char * thirdParty = GetThirdPartyData(thirdPartySize);

            float * raw = GetRawData(rawCount);
            unsigned char * timeStamps = GetTimeStampsStreamData(TIMESTAMP_RAW);

            if (raw) {
                for (int i = 0; i < rawCount; ++i) {
                    int offset = ABM_RAW_PACKAGESIZE * i + ABM_RAW_CHANNEL1_OFFSET;

                    raw_data.insert(raw_data.end(), raw + offset, raw + offset + num_channels);
                    offset = ABM_TIME_PACKAGESIZE * i;
                    int new_ts = ConvertTimestamp(timeStamps + offset);

                    if (i % 2 == 0) {
                        // sensor packets come in pairs; we artificially move the timestamp of
                        // the earlier part of each pair back one sample period for consistency
                        new_ts -= ABM_SAMPLELENGTH;
                    }
                    raw_data_ts.push_back(new_ts);
                }
            }

            if (thirdParty) {
                int numEvents = thirdPartySize / ABM_TP_PACKAGESIZE;
                for (int i = 0; i < numEvents; ++i) {
                    int offset = i * ABM_TP_PACKAGESIZE;
                    events_ts.push_back(ConvertTimestamp(thirdParty + offset + ABM_TP_TIME_OFFSET));
                    events.push_back(thirdParty[offset + ABM_TP_DATA_OFFSET]);
                }
            }
        }

        {
            concurrency::critical_section::scoped_lock lock(queue_mutex);

            while (!raw_data_ts.empty()) {
                while (events_ts.size() && events_ts.front() <= raw_data_ts.front()) {
                    latest_event = events.front();

                    events.pop_front();
                    events_ts.pop_front();
                }

                DataBlock db;
                db.timestamp = raw_data_ts.front();
                db.thirdparty = latest_event;

                for (int i = 0; i < num_channels; ++i) {
                    db.data.push_back(raw_data.front());
                    raw_data.pop_front();
                }

                data_queue.push_back(db);
                raw_data_ts.pop_front();
            }
        }
        assert(raw_data.empty());

        Sleep(10); // called 100 times per second
        if (!running) {
            return 0;
        }
    }
    return 0;
}