Skip to content

Commit

Permalink
Merge pull request #109 from AlexeySmolenchuk/MSVC_friendly
Browse files Browse the repository at this point in the history
* AlexeySmolenchuk/MSVC_friendly:
  add "Cd" channel
  fix opacity by swapping logic
  check by sorted indices (order not guarantied for different platforms)
  widnows friendly build
  • Loading branch information
davvid committed Jan 28, 2025
2 parents d567c52 + 7f0bb37 commit 5c8554b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/lib/core/KdTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#ifndef KdTree_h
#define KdTree_h
#if defined(__clang__) && defined(_LIBCPP_VERSION)
#if defined(__clang__) && defined(_LIBCPP_VERSION) || defined(_MSC_VER)
#include <numeric>
#elif defined(__GNUC__)
#include <ext/numeric>
Expand Down Expand Up @@ -290,7 +290,7 @@ void KdTree<k>::setPoints(const float* p, int n)

// assign sequential ids
_ids.resize(n);
#if defined(__clang__) && defined(_LIBCPP_VERSION)
#if defined(__clang__) && defined(_LIBCPP_VERSION) || defined(_MSC_VER)
std::iota(_ids.begin(), _ids.end(), 0);
#elif defined(__GNUC__)
__gnu_cxx::iota(_ids.begin(), _ids.end(), 0);
Expand Down
8 changes: 4 additions & 4 deletions src/tests/testcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ int main(int argc,char* argv[])
p->addParticle();
float* pos=p->dataWrite<float>(attr,0);
pos[0]=1;pos[1]=2;pos[2]=3;
Partio::write("/tmp/test.bgeo",*p);
Partio::write("test.bgeo",*p);
p->release();

Partio::ParticlesInfo* p1=Partio::readCached("/tmp/test.bgeo",false);
Partio::ParticlesInfo* p2=Partio::readCached("/tmp/test.bgeo",false);
Partio::ParticlesInfo* p1=Partio::readCached("test.bgeo",false);
Partio::ParticlesInfo* p2=Partio::readCached("test.bgeo",false);
assert(p1==p2);
p1->release();p2->release();
Partio::ParticlesInfo* p3=Partio::readCached("/tmp/test.bgeo",false);
Partio::ParticlesInfo* p3=Partio::readCached("test.bgeo",false);
p3->release();
//assert(p2!=p3);

Expand Down
17 changes: 11 additions & 6 deletions src/tests/testkdtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#include <iostream>
#include <cmath>
#include <stdexcept>
#include <algorithm>
#define GRIDN 9


Expand Down Expand Up @@ -86,17 +87,19 @@ int main(int argc,char *argv[])

foo->findNPoints(point, 5, 0.15f, indices, dists);
TESTASSERT (indices.size() == 5);


std::sort(indices.begin(), indices.end());

const float *pos = foo->data<float>(posAttr, indices[0]);
TESTASSERT (pos[0] == 0.375f && pos[1] == 0.5 && pos[2] == 0.5);
pos = foo->data<float>(posAttr, indices[1]);
TESTASSERT (pos[0] == 0.625 && pos[1] == 0.5 && pos[2] == 0.5);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.5);
pos = foo->data<float>(posAttr, indices[2]);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.625);
pos = foo->data<float>(posAttr, indices[3]);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.625 && pos[2] == 0.5);
pos = foo->data<float>(posAttr, indices[4]);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.5);
TESTASSERT (pos[0] == 0.625 && pos[1] == 0.5 && pos[2] == 0.5);

std::cout << "Test passed\n";
}
Expand All @@ -109,17 +112,19 @@ int main(int argc,char *argv[])
float finalDist;
int returned=foo->findNPoints(point, 5, 0.15f, indices, dists,&finalDist);
TESTASSERT(returned == 5);


std::sort(indices, indices + returned);

const float *pos = foo->data<float>(posAttr, indices[0]);
TESTASSERT (pos[0] == 0.375f && pos[1] == 0.5 && pos[2] == 0.5);
pos = foo->data<float>(posAttr, indices[1]);
TESTASSERT (pos[0] == 0.625 && pos[1] == 0.5 && pos[2] == 0.5);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.5);
pos = foo->data<float>(posAttr, indices[2]);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.625);
pos = foo->data<float>(posAttr, indices[3]);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.625 && pos[2] == 0.5);
pos = foo->data<float>(posAttr, indices[4]);
TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.5);
TESTASSERT (pos[0] == 0.625 && pos[1] == 0.5 && pos[2] == 0.5);

std::cout << "Test passed\n";
}
Expand Down
6 changes: 3 additions & 3 deletions src/tools/partview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void drawParticles()
//cout << "not inited" << endl;
inited=true;
colorMissing = true;
colorMissing = true;
alphaMissing = true;


glEnable(GL_DEPTH_TEST);
Expand Down Expand Up @@ -139,7 +139,8 @@ static void drawParticles()
if (particles->attributeInfo("pointColor", colorAttr) ||
particles->attributeInfo("color", colorAttr) ||
particles->attributeInfo("rgb", colorAttr) ||
particles->attributeInfo("rgbPP", colorAttr))
particles->attributeInfo("rgbPP", colorAttr) ||
particles->attributeInfo("Cd", colorAttr))
{
//std::cerr<<"Found color attribute "<<std::endl;
colorMissing = false;
Expand All @@ -152,7 +153,6 @@ static void drawParticles()
particles->attributeInfo("opacityPP", alphaAttr) ||
particles->attributeInfo("opacity", alphaAttr))
{
//std::cerr<<"Found alpha attribute "<<std::endl;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
alphaMissing = false;
Expand Down

0 comments on commit 5c8554b

Please sign in to comment.