Giter Club home page Giter Club logo

mniobjparser's Introduction

This package provides a tool to parse MNI OBJ mesh/surface files. Those are generally generated by CIVET as an output of extracting the white/grey matter from MRI data.
Both CIVET and this package are being developed and maintained by MCIN lab.

DEMO, see the examples folder of the repo.
DOCUMENTATION

Read more about the MNI OBJ file format here.

How to

In a npm project

$ npm install --save mniobjparser

Then use import (e.g. in a Rollup project):

import { MniObjParser } from 'mniobjparser';
...
var myParser = new MniObjParser();

In a stand alone webpage

<script src="mniobjparser/dist/mniobjparser.umd.js"></script>
<!-- OR the minified version -->
<script src="mniobjparser/dist/mniobjparser.umd.min.js"></script>

Then use it with a reference to its module:

var myParser = new mniobjparser.MniObjParser();

Then, no matter in what context you are using it, the following is the same. A MNI OBJ file is a (potentially very long) text file, and depending on your project you may waht to open such files from the local machine using a open file dialog or from a distant server with an AJAX request. This is your choice and this quick how to will not cover this part, so in the following we assume that your Javascript code already has access to the very long String content of a MNI OBJ file.

// parse the string content or the MNI OBJ file:
myParser.parse( largeMniObjString )

// Check if the parsing went ok:
if( !parser.isValid() ){
  alert("Invalid MNI OBJ file.\n" + "ERROR: " + parser.getErrorMessage());
  return;
}

// get the position of all the vertices as [x, y, z, x, y, z, ... ]
var positions = parser.getRawVertices();  // Float32Array

// get the index of the vertices involved in faces. These are the index from the "positions" array
// [index0, index1, index2, index0, index1, index2, ... ] , each are triangles
var indices = parser.getShapeRawIndices(); // Uint32Array

// get the list of normal vectors (unit) as [x, y, z, x, y, z, ... ]
var normals = parser.getRawNormals(); // Float32Array

// get all the colors per vertex as [r, g, b, a, r, g, b, a, ... ]
var colors = parser.getRawColors(); // Uint8Array

// get some material information, not mandatory to reconstruct the mesh
var surfaceProperties = parser.getSurfaceProperties(); // object

Then, using ThreeJS (or other) you can rebuild the mesh, just like in this example.

mniobjparser's People

Contributors

jonathanlurie avatar

Watchers

James Cloos avatar  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.