npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

point-cloud-visualiser

v1.3.0

Published

A react component which can be used to visualise point clouds.

Downloads

48

Readme

point-cloud-visualiser

point-cloud-visualiser is a react component which can be used to visualise point clouds (PCs).

Installation

To start using point-cloud-visualiser install using npm:

npm i point-cloud-visualiser

Parameters

The table below defines the parameters which can be passed to the component in order to define the PC.

Parameter | Required? | Description | ------------------- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | points | yes (unless pointFunction is defined) | A 2D array containing all the points to be displayed. See example 1. | pointFunction | yes (unless points is defined) | A function that takes the point number in the range [0,numberOfPoints-1] and returns the point position (x,y,z). See example 2. | numberOfPoints | no (unless pointsFunction is defined) | The total number of points you wish to define in the PC. Ignored in the case points is defined. See example 2. | pointColour | no | The colour asigned to all points within the PC. Examples: "black", "#000000". | pointsColour | no | An array with length equal to the number of points, defining the individual point colours. See example 3. | pointColourFunction | no | A function in the form of: const pointsColour = function(x,y,z,i) { return 0x000000 }. See example 4. | cameraPosition | no | The position of the camera - which points to the origin (0,0,0). Example: [5,20,30]. |

Examples

The following examples show how the parameters defined above can be put to use.

Example 1 - using points parameter

import {PointCloudVisualiser} from 'point-cloud-visualiser'
import './App.css';

function getPoints(numberOfPoints) {
  const points = Array(numberOfPoints)
  for(var i=0 ; i<numberOfPoints; i++) {
    const point = Array(3)
    if(i % 6 == 0) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = (Math.random() * 5) - 2.5
        point[2] = - 0.5
    } else if(i % 6 == 1) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = 2.5
        point[2] = (Math.random() * 1) - 0.5
    } else if(i % 6 == 2) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = (Math.random() * 5) - 2.5
        point[2] = 0.5
    } else if(i % 6 == 3) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = - 2.5
        point[2] = (Math.random() * 1) - 0.5
    } else if(i % 6 == 4) {
        point[0] =  6.5
        point[1] = (Math.random() * 5) - 2.5
        point[2] = (Math.random() * 1) - 0.5
    } else if(i % 6 == 5) {
        point[0] = - 6.5
        point[1]= (Math.random() * 5) - 2.5
        point[2] = (Math.random() * 1) - 0.5
    }
    points[i]=point
  }
  return points
}

function App() {
  return (
    <>
    <PointCloudVisualiser points={getPoints(100000)} />
    </>
    
  );
}

export default App;

The result of the above can be seen below: Example1

Example 2 - using the points function parameter

Example 1 is a good approach where you're reading points in from a file. However when you want to define the points using a function use this approach. The outcome is identical to example 1.

import {PointCloudVisualiser} from 'point-cloud-visualiser'
import './App.css';

function getPoint(i) {
    const point = Array(3)
    if(i % 6 == 0) {
      point[0] = (Math.random() * 13) - 6.5
      point[1] = (Math.random() * 5) - 2.5
      point[2] = - 0.5
    } else if(i % 6 == 1) {
      point[0] = (Math.random() * 13) - 6.5
      point[1] = 2.5
      point[2] = (Math.random() * 1) - 0.5
    } else if(i % 6 == 2) {
      point[0] = (Math.random() * 13) - 6.5
      point[1] = (Math.random() * 5) - 2.5
      point[2] = 0.5
    } else if(i % 6 == 3) {
      point[0] = (Math.random() * 13) - 6.5
      point[1] = - 2.5
      point[2] = (Math.random() * 1) - 0.5
    } else if(i % 6 == 4) {
      point[0] =  6.5
      point[1] = (Math.random() * 5) - 2.5
      point[2] = (Math.random() * 1) - 0.5
    } else if(i % 6 == 5) {
      point[0] = - 6.5
      point[1]= (Math.random() * 5) - 2.5
      point[2] = (Math.random() * 1) - 0.5
    }
    return point
}

function App() {
  return (
    <>
    <PointCloudVisualiser pointFunction={getPoint} numberOfPoints={100000} />
    </>
    
  );
}

export default App;

Examples of how to style the point cloud

The following examples show how the parameters can be used to style the point cloud.

Example 1 - changing the point colour

import {PointCloudVisualiser} from 'point-cloud-visualiser'
import './App.css';

function getPoint(i) {
  const point = Array(3)
  
  var x = Math.random() -0.5
  var y = Math.random() -0.5
  var z = Math.random() -0.5

  point[0] = x * (1 / Math.sqrt(Math.pow(x,2) + Math.pow(y,2)+ Math.pow(z,2))) * 5
  point[1] = y * (1 / Math.sqrt(Math.pow(x,2) + Math.pow(y,2)+ Math.pow(z,2))) * 5
  point[2] = z * (1 / Math.sqrt(Math.pow(x,2) + Math.pow(y,2)+ Math.pow(z,2))) * 5

  return point
}

function App() {
  return (
    <>
    <PointCloudVisualiser pointFunction={getPoint} numberOfPoints={100000} pointColour={'#33E3FF'} />
    </>
    
  );
}

export default App; />

The result of the above can be seen below: Example2

Example 3 - specifying each of the points' colour

import {PointCloudVisualiser} from 'point-cloud-visualiser'
import './App.css';

function getPoints(numberOfPoints) {
  
  const points = Array(numberOfPoints)
  for(var i=0 ; i<numberOfPoints; i++) {
  
  const point = Array(3)
  
  var x = Math.random() -0.5
  var y = Math.random() -0.5
  var z = Math.random() -0.5

  point[0] = x * (1 / Math.sqrt(Math.pow(x,2) + Math.pow(y,2)+ Math.pow(z,2))) * 5
  point[1] = y * (1 / Math.sqrt(Math.pow(x,2) + Math.pow(y,2)+ Math.pow(z,2))) * 5
  point[2] = z * (1 / Math.sqrt(Math.pow(x,2) + Math.pow(y,2)+ Math.pow(z,2))) * 5

  points[i]=point
  }
  return points
}

function getPointsColour(points) {
  const colours = Array(points.length)
  for(var i=0 ; i<points.length ; i++) {
    colours[i] = points[i][1] > 0 ? 0x0057b8 : 0xFFD700
  }
  return colours
}

function App() {

  const numberOfPoints = 100000
  const points = getPoints(numberOfPoints)
  const pointsColour = getPointsColour(points)

  return (
    <>
    <PointCloudVisualiser points={points} pointsColour={pointsColour}/>
    </>
    
  );
}

export default App;

The result of the above can be seen below: Example3

Example 4 - specifying each of the points' colour using a function

The below example allows you to specify the points' colour by passing a function. The function will be passed the points x,y,z location and the index of the point in the points array. a hex value must be returned in response.

import { PointCloudVisualiser } from "point-cloud-visualiser"
import './App.css';

function getPoints(numberOfPoints) {
  const points = Array(numberOfPoints)
  for(var i=0 ; i<numberOfPoints; i++) {
    const point = Array(3)
    if(i > numberOfPoints - (numberOfPoints/2)) {
      point[0] = (Math.random() * 50) - 25
      point[1] = (Math.random() * 20) - 10
      point[2] = (Math.random() * 20) - 10
    } else if(i % 6 === 0) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = (Math.random() * 5) - 2.5
        point[2] = - 1.5
    } else if(i % 6 === 1) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = 2.5
        point[2] = (Math.random() * 3) - 1.5
    } else if(i % 6 === 2) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = (Math.random() * 5) - 2.5
        point[2] = 1.5
    } else if(i % 6 === 3) {
        point[0] = (Math.random() * 13) - 6.5
        point[1] = - 2.5
        point[2] = (Math.random() * 3) - 1.5
    } else if(i % 6 === 4) {
        point[0] =  6.5
        point[1] = (Math.random() * 5) - 2.5
        point[2] = (Math.random() * 3) - 1.5
    } else if(i % 6 === 5) {
        point[0] = - 6.5
        point[1]= (Math.random() * 5) - 2.5
        point[2] = (Math.random() * 3) - 1.5
    }
    points[i]=point
  }
  return points
}

function App() {

  const numberOfPoints = 180000
  const points = getPoints(numberOfPoints)
  const pointsColour = function(x,y,z,i) {
    if(i > numberOfPoints - (numberOfPoints/2)) {
      return 0x000000
    } else if(x === 6.5) {
      return 0xff0000
    } else if(x === - 6.5) {
      return 0xff0000
    } else if(y === 2.5) {
      return 0x00ff00
    } else if(y === -2.5) {
      return 0x00ff00
    } else if(z === 1.5) {
      return 0x0000ff
    } else if(z === -1.5) {
      return 0x0000ff
    }
    return 0x000000;
  }

  return (
    <>
    <PointCloudVisualiser points={points} pointColourFunction={pointsColour}></PointCloudVisualiser>
    </>
    
  );
}

export default App;

The result of the above can be seen below: Example4