Skip to content

Commit 3186666

Browse files
authored
Merge pull request #116 from ComputationalRadiationPhysics/dev
release 1.5.1
2 parents 010bdd2 + 70229f8 commit 3186666

File tree

12 files changed

+92
-43
lines changed

12 files changed

+92
-43
lines changed

lib/ISAACConfig.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# ISAAC_CUDA
1313
# ISAAC_ALPAKA
1414
# ISAAC_JPEG
15+
# ISAAC_AO_BUG_FIX
1516

1617
###############################################################################
1718
# ISAAC
@@ -56,6 +57,8 @@ if ( (NOT ISAAC_CUDA) AND (NOT ISAAC_ALPAKA) )
5657
message( FATAL_ERROR "At least Alpaka or Cuda have to be activated!" )
5758
endif()
5859

60+
option(ISAAC_AO_BUG_FIX "fix ambient occlusion bug" ON)
61+
5962
###############################################################################
6063
# JPEGLIB
6164
###############################################################################

lib/isaac.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#endif
2424

2525

26+
#include <random>
2627
#include <string>
2728
#include <string.h>
2829
#include <jansson.h>

lib/isaac/isaac_kernel.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,9 @@ namespace isaac
757757
normal = start + t0 * dir - particle_pos;
758758
if( t0 < 0 && is_clipped )
759759
{
760+
#if ISAAC_AO_BUG_FIX == 1
761+
color.w = 0;
762+
#endif
760763
normal = -clipping_normal;
761764
}
762765
}
@@ -2275,8 +2278,8 @@ namespace isaac
22752278
for(int i = -3; i <= 3; i++) {
22762279
for(int j = -3; j <= 3; j++) {
22772280
//avoid out of bounds by simple min max
2278-
isaac_int x = MAX(MIN(pixel.x + i * radius, framebuffer_start.x + framebuffer_size.x), framebuffer_start.x);
2279-
isaac_int y = MAX(MIN(pixel.y + j * radius, framebuffer_start.y + framebuffer_size.y), framebuffer_start.y);
2281+
isaac_int x = ISAAC_MAX(ISAAC_MIN(pixel.x + i * radius, framebuffer_start.x + framebuffer_size.x), framebuffer_start.x);
2282+
isaac_int y = ISAAC_MAX(ISAAC_MIN(pixel.y + j * radius, framebuffer_start.y + framebuffer_size.y), framebuffer_start.y);
22802283

22812284
//get the neighbour depth value
22822285
isaac_float depth_sample = gDepth[x + y * framebuffer_size.x].z;

lib/isaac/isaac_version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define ISAAC_VERSION_MAJOR 1
44
#define ISAAC_VERSION_MINOR 5
5-
#define ISAAC_VERSION_PATCH 0
5+
#define ISAAC_VERSION_PATCH 1
66

77
#define ISAAC_PROTOCOL_VERSION_MAJOR 1
88
#define ISAAC_PROTOCOL_VERSION_MINOR 0

server/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ if (ISAAC_GST)
7878
add_definitions(-DISAAC_GST)
7979
endif (ISAAC_GST)
8080

81+
82+
83+
set(ISAAC_MAX_RECEIVE "8388608" CACHE STRING "The size of the reserved buffers for sending and receiving, default of 8 MB should work for up to 4K" )
84+
set(ISAAC_DEFINITIONS ${ISAAC_DEFINITIONS} -DISAAC_MAX_RECEIVE=${ISAAC_MAX_RECEIVE})
85+
add_definitions(${ISAAC_DEFINITIONS})
86+
8187
option(ISAAC_JPEG "Use JPEG compression between visualization and isaac server. Deactivating will not work with big images. And with big I am talking about bigger than 800x600." ON)
8288
if (ISAAC_JPEG)
8389
find_package(JPEG REQUIRED)

server/src/Broker.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ errorCode Broker::addDataConnector(MetaDataConnector *dataConnector)
6666
return 0;
6767
}
6868

69-
errorCode Broker::addImageConnector(ImageConnector *imageConnector)
69+
errorCode Broker::addImageConnector(ImageConnector *imageConnector, int id)
7070
{
7171
imageConnector->setBroker(this);
7272
ImageConnectorContainer d;
7373
d.connector = imageConnector;
7474
d.thread = 0;
75-
imageConnectorList.push_back(d);
75+
imageConnectorList[id] = d;
7676
if (imageConnector->showClient)
7777
{
7878
json_t* element = json_object();
@@ -294,8 +294,8 @@ errorCode Broker::run()
294294
}
295295
for (auto it = imageConnectorList.begin(); it != imageConnectorList.end(); it++)
296296
{
297-
printf("Launching %s\n",(*it).connector->getName().c_str());
298-
pthread_create(&((*it).thread),NULL,Runable::run_runable,(*it).connector);
297+
printf("Launching %s\n",(*it).second.connector->getName().c_str());
298+
pthread_create(&((*it).second.thread),NULL,Runable::run_runable,(*it).second.connector);
299299
}
300300
while (force_exit == 0)
301301
{
@@ -349,7 +349,7 @@ errorCode Broker::run()
349349
container->image->suicide();
350350
else
351351
for(auto ic=imageConnectorList.begin();ic!=imageConnectorList.end();ic++)
352-
(*ic).connector->masterSendMessage(container);
352+
(*ic).second.connector->masterSendMessage(container);
353353
}
354354
else
355355
{
@@ -412,7 +412,7 @@ errorCode Broker::run()
412412
dc = dc->next;
413413
}
414414
for (auto it = imageConnectorList.begin(); it != imageConnectorList.end(); it++)
415-
(*it).connector->masterSendMessage(new ImageBufferContainer(GROUP_ADDED,NULL,group,1));
415+
(*it).second.connector->masterSendMessage(new ImageBufferContainer(GROUP_ADDED,NULL,group,1));
416416
}
417417
}
418418
else
@@ -434,7 +434,7 @@ errorCode Broker::run()
434434
dc = dc->next;
435435
}
436436
for (auto it = imageConnectorList.begin(); it != imageConnectorList.end(); it++)
437-
(*it).connector->masterSendMessage(new ImageBufferContainer(GROUP_FINISHED,NULL,group,1));
437+
(*it).second.connector->masterSendMessage(new ImageBufferContainer(GROUP_FINISHED,NULL,group,1));
438438
//Now let's remove the whole group
439439
group->master->group = NULL;
440440
printf("Removed group %i\n",group->id);
@@ -497,11 +497,12 @@ errorCode Broker::run()
497497
{
498498
int id = json_integer_value( json_object_get(message->json_root, "observe id") );
499499
int stream = json_integer_value( json_object_get(message->json_root, "stream") );
500+
//printf("%d\n", stream);
500501
bool dropable = json_boolean_value( json_object_get(message->json_root, "dropable") );
501-
if ( stream < 0 )
502-
stream = 0;
503-
if ( stream >= int(imageConnectorList.size()) )
504-
stream = imageConnectorList.size()-1;
502+
//if ( stream < 0 )
503+
// stream = 0;
504+
//if ( stream >= int(imageConnectorList.size()) )
505+
// stream = imageConnectorList.size()-1;
505506
const char* url = json_string_value( json_object_get(message->json_root, "url") );
506507
void* ref = (void*)dc->t;
507508
dc->t->observe( id, stream, dropable );
@@ -518,6 +519,7 @@ errorCode Broker::run()
518519
}
519520
if (group)
520521
{
522+
//printf("%d\n", stream);
521523
json_t *js, *root = json_object();
522524
if (json_array_size( js = json_object_get( group->initData, "projection") ) == 16)
523525
json_object_set( root, "projection", js );
@@ -529,7 +531,8 @@ errorCode Broker::run()
529531
json_object_set( root, "distance", js );
530532
json_object_set_new( root, "type", json_string( "update" ) );
531533
dc->t->masterSendMessage(new MessageContainer(UPDATE,root));
532-
imageConnectorList[ stream ].connector->masterSendMessage(new ImageBufferContainer(GROUP_OBSERVED,NULL,group,1,url,ref));
534+
if(imageConnectorList.find(stream) != imageConnectorList.end())
535+
imageConnectorList[ stream ].connector->masterSendMessage(new ImageBufferContainer(GROUP_OBSERVED,NULL,group,1,url,ref));
533536
//Send request for (transfer) functions and most recent frame
534537
char buffer[] =
535538
"{\"type\": \"feedback\", \"request\": \"transfer\"} "
@@ -560,7 +563,8 @@ errorCode Broker::run()
560563
}
561564
it = it->next;
562565
}
563-
if (group)
566+
// TODO: Check for define, not necessary if not activated
567+
if (group && imageConnectorList.find(stream) != imageConnectorList.end())
564568
imageConnectorList[ stream ].connector->masterSendMessage(new ImageBufferContainer(GROUP_OBSERVED_STOPPED,NULL,group,1,url,ref));
565569
}
566570
if (message->type == CLOSED)
@@ -584,23 +588,22 @@ errorCode Broker::run()
584588
}
585589
dc = next;
586590
}
587-
588591
///////////////////////////////////////
589592
// Iterate over all image connectors //
590593
///////////////////////////////////////
591594
for (auto it = imageConnectorList.begin(); it != imageConnectorList.end(); it++)
592595
{
593-
while (ImageBufferContainer* message = (*it).connector->masterGetMessage())
596+
while (ImageBufferContainer* message = (*it).second.connector->masterGetMessage())
594597
{
595598
if (message->type == REGISTER_STREAM)
596599
{
597600
pthread_mutex_lock(&message->group->streams_mutex);
598-
message->group->streams[(*it).connector->getName()].insert( std::pair< void*,std::string >( message->reference, std::string((char*)message->image->buffer) ));
601+
message->group->streams[(*it).second.connector->getName()].insert( std::pair< void*,std::string >( message->reference, std::string((char*)message->image->buffer) ));
599602
pthread_mutex_unlock(&message->group->streams_mutex);
600603
json_t* root = json_object();
601604
json_object_set_new( root, "type", json_string ("register video") );
602605
json_object_set_new( root, "name", json_string ( message->group->getName().c_str() ) );
603-
json_object_set_new( root, "connector", json_string ( (*it).connector->getName().c_str() ) );
606+
json_object_set_new( root, "connector", json_string ( (*it).second.connector->getName().c_str() ) );
604607
json_object_set_new( root, "reference", json_integer ( (long)message->reference ) );
605608
ThreadList<MetaDataClient*>::ThreadListContainer_ptr dc = dataClientList.getFront();
606609
while (dc)
@@ -651,8 +654,8 @@ errorCode Broker::run()
651654
}
652655
for (auto it = imageConnectorList.begin(); it != imageConnectorList.end(); it++)
653656
{
654-
printf("Asking %s to exit\n",(*it).connector->getName().c_str());
655-
(*it).connector->masterSendMessage(new ImageBufferContainer(IMG_FORCE_EXIT,NULL,NULL,1));
657+
printf("Asking %s to exit\n",(*it).second.connector->getName().c_str());
658+
(*it).second.connector->masterSendMessage(new ImageBufferContainer(IMG_FORCE_EXIT,NULL,NULL,1));
656659
}
657660
for (auto it = dataConnectorList.begin(); it != dataConnectorList.end(); it++)
658661
{
@@ -661,8 +664,8 @@ errorCode Broker::run()
661664
}
662665
for (auto it = imageConnectorList.begin(); it != imageConnectorList.end(); it++)
663666
{
664-
pthread_join((*it).thread,NULL);
665-
printf("%s finished\n",(*it).connector->getName().c_str());
667+
pthread_join((*it).second.thread,NULL);
668+
printf("%s finished\n",(*it).second.connector->getName().c_str());
666669
}
667670
signal(SIGINT, SIG_DFL);
668671
return 0;

server/src/Broker.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ImageConnector;
3030
#include "InsituConnectorMaster.hpp"
3131
#include <memory>
3232
#include <map>
33+
#include <unordered_map>
3334

3435
typedef struct MetaDataConnectorContainer_struct
3536
{
@@ -102,7 +103,7 @@ class Broker
102103
Broker(std::string name,int inner_port,std::string interface);
103104
~Broker();
104105
errorCode addDataConnector(MetaDataConnector *dataConnector);
105-
errorCode addImageConnector(ImageConnector *imageConnector);
106+
errorCode addImageConnector(ImageConnector *imageConnector, int id);
106107
MetaDataClient* addDataClient();
107108
void receiveVideo(InsituConnectorGroup* group,uint8_t* video_buffer,char* payload);
108109
errorCode run();
@@ -114,7 +115,7 @@ class Broker
114115
json_t* masterHelloConnectorList;
115116
std::string name;
116117
std::vector< MetaDataConnectorContainer > dataConnectorList;
117-
std::vector< ImageConnectorContainer > imageConnectorList;
118+
std::unordered_map< int, ImageConnectorContainer > imageConnectorList;
118119
ThreadList< InsituConnectorGroup* > insituConnectorGroupList;
119120
ThreadList< MetaDataClient* > dataClientList;
120121
int inner_port;

server/src/Common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
#include <string.h>
2020
#include <jansson.h>
2121

22+
#include <iostream>
23+
2224
typedef int ClientRef;
2325
typedef int ObserverRef;
2426
typedef int errorCode;
2527

26-
#define ISAAC_MAX_RECEIVE 4194304 //4 MB
27-
2828
typedef enum
2929
{
3030
FORCE_EXIT = -1,

server/src/InsituConnectorMaster.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ errorCode InsituConnectorMaster::run()
124124
{
125125
int add = recv(fd_array[i].fd,&(con_array[i]->connector->jlcb.buffer[con_array[i]->connector->jlcb.count]),4096,MSG_DONTWAIT);
126126
if (add > 0)
127+
{
127128
con_array[i]->connector->jlcb.count += add;
129+
if(con_array[i]->connector->jlcb.count > ISAAC_MAX_RECEIVE)
130+
{
131+
fprintf(stderr,"Fatal error: Socket received %d bytes but buffer is only %d bytes! To increase the allowed size set ISAAC_MAX_RECEIVE to a higher value.\n",
132+
con_array[i]->connector->jlcb.count, ISAAC_MAX_RECEIVE);
133+
return -1;
134+
}
135+
}
128136
else
129137
break;
130138
}

server/src/WebSocketDataConnector.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sys/stat.h>
2424
#include <fcntl.h>
2525
#include <assert.h>
26+
#include <vector>
2627

2728
#include <syslog.h>
2829
#include <sys/time.h>
@@ -97,7 +98,7 @@ static int callback_isaac(
9798
size_t len )
9899
{
99100
int n, m;
100-
101+
101102
struct per_session_data__isaac *pss = (struct per_session_data__isaac *)user;
102103
Broker** broker_ptr = (Broker**)lws_context_user(lws_get_context(wsi));
103104
Broker* broker = NULL;
@@ -115,10 +116,6 @@ static int callback_isaac(
115116
case LWS_CALLBACK_SERVER_WRITEABLE:
116117
if (pss->client)
117118
{
118-
char* buf = new char[LWS_SEND_BUFFER_PRE_PADDING + ISAAC_MAX_RECEIVE +
119-
LWS_SEND_BUFFER_POST_PADDING];
120-
121-
char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
122119
MessageContainer* message = NULL;
123120
int l = 0;
124121
do
@@ -130,6 +127,7 @@ static int callback_isaac(
130127
{
131128
printf("WebSocketDataConnector: Dropped one dropable package!\n");
132129
delete message;
130+
message = NULL;
133131
l--;
134132
}
135133
if (message) //New message from master sama!
@@ -138,6 +136,17 @@ static int callback_isaac(
138136
char* buffer = json_dumps( message->json_root, 0 );
139137
pthread_mutex_unlock(&MessageContainer::deep_copy_mutex);
140138
n = strlen(buffer);
139+
140+
std::vector<char> buf(LWS_SEND_BUFFER_PRE_PADDING + n + LWS_SEND_BUFFER_POST_PADDING + 1);
141+
if(buf.size() > ISAAC_MAX_RECEIVE)
142+
{
143+
printf("The maximum set size of %d bytes per lws packet was exceeded! To increase the allowed package size set ISAAC_MAX_RECEIVE to a higher value. \n",
144+
ISAAC_MAX_RECEIVE);
145+
fflush(stdout);
146+
}
147+
148+
char *p = buf.data() + LWS_SEND_BUFFER_PRE_PADDING;
149+
141150
sprintf(p,"%s",buffer);
142151
m = lws_write(wsi, (unsigned char*)p, n, LWS_WRITE_TEXT);
143152
free(buffer);
@@ -148,10 +157,10 @@ static int callback_isaac(
148157
return -1;
149158
}
150159
delete message;
160+
message = NULL;
151161
}
152162
}
153163
while (l > 1 && !lws_send_pipe_choked(wsi));
154-
delete[] buf;
155164
}
156165
break;
157166
//case LWS_CALLBACK_CLOSED:
@@ -160,7 +169,10 @@ static int callback_isaac(
160169
case LWS_CALLBACK_RECEIVE:
161170
if (pss->client)
162171
{
163-
json_t* input = json_loads((const char *)in, 0, NULL);
172+
json_error_t error;
173+
json_t* input = json_loadb((const char *)in, len, 0, &error);
174+
if(!input)
175+
printf("JSON ERROR: %s", error.text);
164176
MessageContainer* message = new MessageContainer(NONE,input);
165177
int finish = (message->type == CLOSED);
166178
json_object_set_new( message->json_root, "url", json_string( pss->url ) );
@@ -172,6 +184,7 @@ static int callback_isaac(
172184

173185
case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
174186
{
187+
printf("callback_isaac: LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION\n");
175188
char name[256];
176189
char rip[256];
177190
lws_get_peer_addresses(wsi,lws_get_socket_fd(wsi),name,256,rip,256);
@@ -206,7 +219,8 @@ errorCode WebSocketDataConnector::init(int port,std::string interface)
206219
{
207220
setlogmask(LOG_UPTO (LOG_DEBUG));
208221
openlog("lwsts", LOG_PID | LOG_PERROR, LOG_DAEMON);
209-
lws_set_log_level(7, lwsl_emit_syslog);
222+
int logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
223+
lws_set_log_level(logs, lwsl_emit_syslog);
210224
struct lws_context_creation_info info;
211225
memset(&info, 0, sizeof info);
212226
info.protocols = protocols;

0 commit comments

Comments
 (0)