Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use cpp11 for simpleraytracer glue to avoid -Wlto warnings #1163

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
igraph_hcass2 <- function(n, ia, ib) {
.Call(`_igraph_igraph_hcass2`, n, ia, ib)
}

getsphere <- function(spos, sradius, scolor, lightpos, lightcolor, swidth, sheight) {
.Call(`_igraph_getsphere`, spos, sradius, scolor, lightpos, lightcolor, swidth, sheight)
}
13 changes: 8 additions & 5 deletions R/plot.shapes.R
Original file line number Diff line number Diff line change
Expand Up @@ -1074,11 +1074,14 @@ mypie <- function(x, y, values, radius, edges = 200, col = NULL, angle = 45,
## Need to create a separate image for every different vertex color
allcols <- unique(vertex.color)
images <- lapply(allcols, function(col) {
img <- .Call(R_igraph_getsphere,
pos = c(0.0, 0.0, 10.0), radius = 7.0,
color = col2rgb(col) / 255, bgcolor = c(0, 0, 0),
lightpos = list(c(-2, 2, 2)), lightcolor = list(c(1, 1, 1)),
width = 100L, height = 100L
img <- getsphere(
spos = c(0.0, 0.0, 10.0),
sradius = 7.0,
scolor = col2rgb(col) / 255,
lightpos = list(c(-2, 2, 2)),
lightcolor = list(c(1, 1, 1)),
swidth = 100L,
sheight = 100L
)
as.raster(img)
})
Expand Down
10 changes: 8 additions & 2 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ extern "C" SEXP _igraph_igraph_hcass2(SEXP n, SEXP ia, SEXP ib) {
return cpp11::as_sexp(igraph_hcass2(cpp11::as_cpp<cpp11::decay_t<int>>(n), cpp11::as_cpp<cpp11::decay_t<cpp11::integers>>(ia), cpp11::as_cpp<cpp11::decay_t<cpp11::integers>>(ib)));
END_CPP11
}
// simpleraytracer.cpp
SEXP getsphere(cpp11::doubles spos, double sradius, cpp11::doubles scolor, cpp11::list lightpos, cpp11::list lightcolor, int swidth, int sheight);
extern "C" SEXP _igraph_getsphere(SEXP spos, SEXP sradius, SEXP scolor, SEXP lightpos, SEXP lightcolor, SEXP swidth, SEXP sheight) {
BEGIN_CPP11
return cpp11::as_sexp(getsphere(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles>>(spos), cpp11::as_cpp<cpp11::decay_t<double>>(sradius), cpp11::as_cpp<cpp11::decay_t<cpp11::doubles>>(scolor), cpp11::as_cpp<cpp11::decay_t<cpp11::list>>(lightpos), cpp11::as_cpp<cpp11::decay_t<cpp11::list>>(lightcolor), cpp11::as_cpp<cpp11::decay_t<int>>(swidth), cpp11::as_cpp<cpp11::decay_t<int>>(sheight)));
END_CPP11
}

extern "C" {
/* .Call calls */
Expand Down Expand Up @@ -200,7 +207,6 @@ extern SEXP R_igraph_get_stochastic_sparse(void *, void *, void *);
extern SEXP R_igraph_get_subisomorphisms_vf2(void *, void *, void *, void *, void *, void *);
extern SEXP R_igraph_get_widest_path(void *, void *, void *, void *, void *);
extern SEXP R_igraph_get_widest_paths(void *, void *, void *, void *, void *);
extern SEXP R_igraph_getsphere(void *, void *, void *, void *, void *, void *, void *, void *);
extern SEXP R_igraph_girth(void *, void *);
extern SEXP R_igraph_global_efficiency(void *, void *, void *);
extern SEXP R_igraph_gomory_hu_tree(void *, void *);
Expand Down Expand Up @@ -659,7 +665,6 @@ static const R_CallMethodDef CallEntries[] = {
{"R_igraph_get_subisomorphisms_vf2", (DL_FUNC) &R_igraph_get_subisomorphisms_vf2, 6},
{"R_igraph_get_widest_path", (DL_FUNC) &R_igraph_get_widest_path, 5},
{"R_igraph_get_widest_paths", (DL_FUNC) &R_igraph_get_widest_paths, 5},
{"R_igraph_getsphere", (DL_FUNC) &R_igraph_getsphere, 8},
{"R_igraph_girth", (DL_FUNC) &R_igraph_girth, 2},
{"R_igraph_global_efficiency", (DL_FUNC) &R_igraph_global_efficiency, 3},
{"R_igraph_gomory_hu_tree", (DL_FUNC) &R_igraph_gomory_hu_tree, 2},
Expand Down Expand Up @@ -927,6 +932,7 @@ static const R_CallMethodDef CallEntries[] = {
{"R_igraph_write_graph_ncol", (DL_FUNC) &R_igraph_write_graph_ncol, 4},
{"R_igraph_write_graph_pajek", (DL_FUNC) &R_igraph_write_graph_pajek, 2},
{"UUID_gen", (DL_FUNC) &UUID_gen, 1},
{"_igraph_getsphere", (DL_FUNC) &_igraph_getsphere, 7},
{"_igraph_igraph_hcass2", (DL_FUNC) &_igraph_igraph_hcass2, 3},
{"make_lazy", (DL_FUNC) &make_lazy, 3},
{"make_lazy_dots", (DL_FUNC) &make_lazy_dots, 2},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,57 @@
/* -*- mode: C -*- */
/*
/*
IGraph library R interface.
Copyright (C) 2005-2012 Gabor Csardi <csardi.gabor@gmail.com>
334 Harvard street, Cambridge, MA 02139 USA

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA

*/

#include "igraph.h"
#include "igraph_error.h"

#include "RayTracer.h"
#include "Sphere.h"
#include "vendor/simpleraytracer/RayTracer.h"
#include "vendor/simpleraytracer/Sphere.h"

#include "config.h"

#include <R.h>
#include <Rinternals.h>
#include <cpp11.hpp>
#include <Rdefines.h>

using namespace igraph;

extern "C" {

SEXP R_igraph_getsphere(SEXP pos, SEXP radius, SEXP color, SEXP bgcolor,
SEXP lightpos, SEXP lightcolor, SEXP width,
SEXP height) {
[[cpp11::register]]
SEXP getsphere(
cpp11::doubles spos, double sradius, cpp11::doubles scolor,
cpp11::list lightpos, cpp11::list lightcolor, int swidth, int sheight) {

/* All error checking is done at the R level */

int i;
double *spos=REAL(pos);
double *scolor=REAL(color);
int no_lights=GET_LENGTH(lightpos);
size_t no_lights=lightpos.size();
RayTracer* p_ray_tracer;
Sphere * sphere;
int swidth=INTEGER(width)[0];
int sheight=INTEGER(height)[0];
Sphere* sphere;
int nopixels=swidth * sheight;
SEXP result, dim;
Image image;

p_ray_tracer = new RayTracer();
p_ray_tracer->EyePoint(Point(0,0,0));
p_ray_tracer->EyePoint(Point(0,0,0));

for (i=0; i<no_lights; i++) {
double *lpos=REAL(VECTOR_ELT(lightpos, i));
double *lcol=REAL(VECTOR_ELT(lightcolor, i));
Expand All @@ -66,16 +60,18 @@ SEXP R_igraph_getsphere(SEXP pos, SEXP radius, SEXP color, SEXP bgcolor,
light->LightColor(Color(lcol[0], lcol[1], lcol[2]));
p_ray_tracer->AddLight(light);
}
sphere = new Sphere(Point(spos[0], spos[1], spos[2]), REAL(radius)[0]);

sphere = new Sphere(Point(spos[0], spos[1], spos[2]), sradius);
sphere->ShapeColor(Color(scolor[0], scolor[1], scolor[2]));
p_ray_tracer->AddShape(sphere);

PROTECT(result=NEW_NUMERIC(nopixels * 4));
PROTECT(dim=NEW_INTEGER(3));
INTEGER(dim)[0]=swidth; INTEGER(dim)[1]=sheight; INTEGER(dim)[2]=4;
INTEGER(dim)[0]=swidth;
INTEGER(dim)[1]=sheight;
INTEGER(dim)[2]=4;
SET_DIM(result, dim);

image.width=swidth;
image.height=sheight;
image.red=REAL(result);
Expand All @@ -85,9 +81,7 @@ SEXP R_igraph_getsphere(SEXP pos, SEXP radius, SEXP color, SEXP bgcolor,

p_ray_tracer->RayTrace(image);
delete p_ray_tracer;

UNPROTECT(2);
return result;
}

} // extern C
Loading
Loading