Code Monkey home page Code Monkey logo

unityvolumerender's Introduction

Unity Volume Render

Volume Render for Unity, inlcude suface volume render and direct volume render. Volume dataset can be raw data or dicom file.

Volume Render

  • Ray-Casting
float3 objViewDir;
float3 startPosition;
for (int i = 0; i < MAX_SAMPLE_COUNT; i++) {
    float3 uvw = startPosition + 0.5;
    if (outside) break;
    // getDensity(uvw);
    // calculate color
    // next pos
    startPosition += objViewDir * SAMPLE_STEP_SIZE;
}

image

  • Phong Lighting Model
float3 ambient = float3(ka, ka, ka) * tfColor;
float3 diffuse = float3(kd, kd, kd) * max(dot(N, L), 0) * tfColor;
float3 specular = float3(ks, ks, ks) * pow(max(dot(V, F), 0), power) * tfColor;
float3 color = ambient + diffuse + specular;

Color Map

  • generate alphamap and colormap
Texture2D texture = new Texture2D(TEXTURE_WIDTH, TEXTURE_HEIGHT, TextureFormat.RGBAFloat, false);
Color[] tfCols = new Color[TEXTURE_WIDTH * TEXTURE_HEIGHT];
List<TFColourControlPoint> cols;
List<TFAlphaControlPoint> alphas;
for (int iX = 0; iX < TEXTURE_WIDTH; iX++)
{
    // calculate color from cols and alphas 
    Color pixCol;
    // set value
    for (int iY = 0; iY < TEXTURE_HEIGHT; iY++)
    {
        tfCols[iX + iY * TEXTURE_WIDTH] = pixCol;
    }
}

image image image

DICOM

dicom format: https://it.wikipedia.org/wiki/DICOM

fo-dicom:https://github.com/fo-dicom/fo-dicom

FileStream fs = File.OpenRead(filepath);
DicomFile dcmFile = DicomFile.Open(fs);
DicomImage dcmImage = new DicomImage(dcmFile.Dataset);
int width = dcmImage.Width;
int height = dcmImage.Height;

// read tag info
slope = dcmFile.Dataset.Get<int>(DicomTag.RescaleSlope);
intercept = dcmFile.Dataset.Get<int>(DicomTag.RescaleIntercept);
......

// store CT values
int n = width * height;
int[] data = new int[n];
DicomPixelData header = DicomPixelData.Create(dcmFile.Dataset);
var pixelData = PixelDataFactory.Create(header, 0);
pixelData.Render(null, data);
for (int i = 0; i < n; i++)
{
    int value = data[i];
    float hounsfieldValue = value * slope + intercept;
    short ct = (short)Mathf.Clamp(hounsfieldValue, -1024.0f, 3071.0f);
}

DICOM source

Screenshot

image image

unityvolumerender's People

Contributors

adamwu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.