<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
All working now, I had an ordering issue. I was resetting the renderingEngine to default before I had set my channel colours.<div>So for future reference, what I ended up using is:</div><div><br></div><div>//Get our pixel object with the channel objects</div><div><span style="font-size: 10pt; ">std::string query = "select p from Pixels p join fetch p.channels as c join fetch c.logicalChannel as lc where p.id=:pid";</span></div><div><div>omero::sys::ParametersIPtr params = new omero::sys::ParametersI();</div><div>params-&gt;add("pid", omero::rtypes::rlong(pixid));</div><div>omero::api::IObjectList resultobjs = queryService-&gt;findAllByQuery(query, params);</div><div>if(resultobjs.empty())&nbsp;</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("ERROR: Could not find pixels object\n");</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return;</div><div>}</div><div><br></div><div>//Set the colours for each channel object</div><div><span style="font-size: 10pt; ">pixels = omero::model::PixelsPtr::dynamicCast(resultobjs[0]);</span></div><div>for(int c=0; c&lt;csize; c++)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>omero::model::ChannelPtr chan = pixels-&gt;getChannel(c);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>omero::model::IObjectPtr obj = queryService-&gt;get("Channel", chan-&gt;getId()-&gt;getValue());</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>chan = omero::model::ChannelPtr::dynamicCast(obj);</div><div><span class="Apple-tab-span" style="font-size: 10pt; white-space: pre; ">        </span><span style="font-size: 10pt; ">chan-&gt;setRed(omero::rtypes::rint(255));</span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>chan-&gt;setGreen(omero::rtypes::rint(0));</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>chan-&gt;setBlue(omero::rtypes::rint(0));</div><div><span class="Apple-tab-span" style="font-size: 10pt; white-space: pre; ">        </span><span style="font-size: 10pt; ">chan-&gt;setAlpha(omero::rtypes::rint(255));</span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>sf-&gt;getUpdateService()-&gt;saveObject(chan);</div><div>}</div><div><br></div><div>//delete the render? settings</div><div>sf-&gt;getDeleteService()-&gt;deleteSettings(imageID);</div><div><br></div><div>//set the global min/max per channel</div><div><span style="font-size: 10pt; ">for(int i=0; i&lt;csize; i++)</span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pixelsService-&gt;setChannelGlobalMinMax(pixid, i, 0, 255);</div><div><br></div><div><span style="font-size: 10pt; ">//reset defaults for the rendering</span></div><div><span style="font-size: 10pt; ">renderingEngine-&gt;lookupPixels(pixid);</span></div><div>if(!renderingEngine-&gt;lookupRenderingDef(pixid))</div><div>{</div><div>&nbsp; &nbsp; &nbsp; &nbsp;renderingEngine-&gt;resetDefaults();</div><div>}</div><div><br></div><div>Hopefully this is now the correct way to do things...</div><div>Thanks for all the help,</div><div><br></div><div>J.</div><div><br></div><div><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: jeromeavondo@msn.com<br>To: will@lifesci.dundee.ac.uk<br>Date: Thu, 22 Mar 2012 17:13:56 +0000<br>CC: ome-devel@lists.openmicroscopy.org.uk<br>Subject: Re: [ome-devel] RenderingEngine: setting channel colours<br><br>

<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
<style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}

</style>
<div dir="ltr">
Ignore the&nbsp;"omero::OptimisticLockException"&nbsp;&nbsp;error, I had some code downstream that was causing the&nbsp;exception.<div>No more exceptions now, but still not setting the channel colours ...</div><div><br></div><div>J.<br></div><div><br></div><div><div id="ecxSkyDrivePlaceholder"></div><hr id="ecxstopSpelling">From: jeromeavondo@msn.com<br>To: will@lifesci.dundee.ac.uk<br>Date: Thu, 22 Mar 2012 15:21:22 +0000<br>CC: ome-devel@lists.openmicroscopy.org.uk<br>Subject: Re: [ome-devel] RenderingEngine: setting channel colours<br><br>



<style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}
</style>
<div dir="ltr">
Apologies&nbsp;I meant this thread:<div><a href="http://www.openmicroscopy.org/community/viewtopic.php?f=6&amp;t=694" style="font-size:10pt" target="_blank">http://www.openmicroscopy.org/community/viewtopic.php?f=6&amp;t=694</a><span style="font-size:10pt">&nbsp;</span></div><div><br></div><div>J.</div><div><br><div><div id="ecxSkyDrivePlaceholder"></div><hr id="ecxstopSpelling">From: jeromeavondo@msn.com<br>To: will@lifesci.dundee.ac.uk<br>Date: Thu, 22 Mar 2012 15:18:54 +0000<br>CC: ome-devel@lists.openmicroscopy.org.uk<br>Subject: Re: [ome-devel] RenderingEngine: setting channel colours<br><br>



<style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}
</style>
<div dir="ltr">
<div>Hi Will,</div><div><br></div><div>Thanks for the info...</div><div><span style="font-size:10pt">I saw that thread, but kept getting an "omero::OptimisticLockException" when trying that approach...</span></div><div><br></div><div>So I was&nbsp;following&nbsp;this thread, since it helped greatly to allow me to upload data...</div><div><a href="https://www.openmicroscopy.org/community/viewtopic.php?f=6&amp;t=768" style="font-size:10pt" target="_blank">https://www.openmicroscopy.org/community/viewtopic.php?f=6&amp;t=768</a></div><div><br></div><div>Just to make sure I understand the difference between setting channel colours&nbsp;<span style="font-size:10pt">via the RenderingEngine vs Channel objects....</span></div><div>The RenderingEngine is a per user setting, whilst doing it on the Channel object will make it the default for all users?</div><div><br></div><div>Using your code, I changed mine to the following, however I still get the <span style="font-size:10pt">"omero::OptimisticLockException"...&nbsp;</span></div><div><br></div><div><div>&nbsp; &nbsp; &nbsp; &nbsp; std::string query = "select p from Pixels p join fetch p.channels as c join fetch c.logicalChannel as lc where p.id=:pid";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; omero::sys::ParametersIPtr params = new omero::sys::ParametersI();</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>params-&gt;add("pid", omero::rtypes::rlong(pixid));</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>omero::api::IObjectList resultobjs = queryService-&gt;findAllByQuery(query, params);</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>if(resultobjs.empty())&nbsp;</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>{</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>printf("ERROR: Could not find pixels object\n");</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>return;</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>pixels = omero::model::PixelsPtr::dynamicCast(resultobjs[0]);</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>for(int c=0; c&lt;csize; c++)</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>{</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>omero::model::ChannelPtr chan = pixels-&gt;getChannel(c);</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>omero::model::IObjectPtr obj = queryService-&gt;get("Channel", chan-&gt;getId()-&gt;getValue());</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>chan = omero::model::ChannelPtr::dynamicCast(obj);<span class="ecxApple-tab-span" style="white-space:pre">        </span></div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>chan-&gt;setRed(omero::rtypes::rint(0));</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>chan-&gt;setGreen(omero::rtypes::rint(255));</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>chan-&gt;setBlue(omero::rtypes::rint(0));</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>chan-&gt;setAlpha(omero::rtypes::rint(255));</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>gateway-&gt;saveObject(chan);</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>}</div><div>&nbsp; &nbsp; &nbsp; &nbsp;sf-&gt;getDeleteService()-&gt;deleteSettings(imageID);</div></div><div><br></div><div>Any idea what I'm doing wrong?</div><div>Thanks!</div><div><br></div><div>J.</div><div><br></div><div>Subject: Re: [ome-devel] RenderingEngine: setting channel colours<br>From: will@lifesci.dundee.ac.uk<br>Date: Thu, 22 Mar 2012 13:03:52 +0000<br>CC: jeromeavondo@msn.com; ome-devel@lists.openmicroscopy.org.uk<br>To: will@lifesci.dundee.ac.uk<br><br>

<div>Hi Jerome,</div><div><br></div><div>You can also see this discussed on our forums (Python again I'm afraid)</div><div><br></div><a href="https://www.openmicroscopy.org/community/viewtopic.php?f=6&amp;t=768" target="_blank">https://www.openmicroscopy.org/community/viewtopic.php?f=6&amp;t=768</a><div><br></div><div>which was the first hit when I Googled:</div><div>omero forum setting channel colours</div><div><br></div><div>Cheers,</div><div><br></div><div>&nbsp; Will.&nbsp;</div><div><br></div><div><br><div><br><div><div>On 22 Mar 2012, at 13:00, Will Moore wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div style="word-wrap:break-word">Hi Jerome,<div><br></div><div>The best way of doing this is to set the colours on the Channels themselves, then reset the default rendering settings.</div><div>This means that whenever any user resets their rendering settings on the image, they will default to the 'correct' colours.&nbsp;</div><div><br></div><div>Here's some (pseudo code) of what I'm doing in Python - Hopefully you can work out the C++</div><div>Not sure if you'll have to reload as I'm doing. Try it and see.</div><div><br></div><div>You can get channels via pixels,</div><div>EITHER via the rendering engine (once you've set Ids etc)...</div><div><br></div><div>pixels &nbsp;=&nbsp;re.getPixels()</div><div><br></div><div><br></div><div>OR via the query service...</div><div><br></div><div><div>pid = image.getPrimaryPixels().getId().getValue()</div><div>params = omero.sys.Parameters()</div><div>params.map = {"pid": rlong(pid)}</div><div>query = "select p from Pixels p join fetch p.channels as c join fetch c.logicalChannel as lc where p.id=:pid"</div><div>pixels = session.getQueryService().findByQuery(query, params)</div></div><div><br></div><div>for c in pixels.iterateChannels():</div><div><span class="ecxApple-tab-span" style="white-space:pre">        # </span>???&nbsp;<span class="ecxApple-tab-span" style="white-space:pre">need to reload channels to avoid optimistic lock on update</span>&nbsp;???&nbsp;<span class="ecxApple-tab-span" style="white-space:pre">
        </span>c<span class="ecxApple-tab-span" style="white-space:pre"> = conn.getQueryService().get("Channel", c.id</span>.val<span class="ecxApple-tab-span" style="white-space:pre">)        </span># could try to skip this step</div><div><br></div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>c.red = omero.rtypes.rint(r)</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>c.green = omero.rtypes.rint(g)</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>c.blue = omero.rtypes.rint(b)</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>c.alpha = omero.rtypes.rint(255)</div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>session.getUpdateService().saveObject(c)</div><div><br></div><div><br></div><div>Than reset&nbsp;</div><div>session.getDeleteService().deleteSettings(imageId)</div><div><br></div><div><div>If this doesn't work, maybe also try:</div><div>renderingEngine.resetDefaults()</div></div><div><br></div><div><br></div><div>&nbsp;Let us know how you get on,</div><div><br></div><div><br></div><div>&nbsp; &nbsp;Will</div><div><br></div><div><br></div><div><br></div><div><div><div>On 22 Mar 2012, at 12:11, Jerome Avondo wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div class="ecxhmmessage" style="font-size:10pt;font-family:Tahoma"><div dir="ltr">Hi,<div><br></div><div>I am trying to set the rendering colours for an image I upload to the server via the C++ API...</div><div>The image upload is all good, but I am a little confused with setting the rendering options...</div><div><span style="font-size:10pt">I am uploading a 3 channel image, and I set the render settings as follows:</span></div><div><br></div><div><span class="ecxApple-tab-span" style="font-size:10pt;white-space:pre">        </span><span style="font-size:10pt">for(int c=0; c&lt;csize; c++)</span></div><div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>{</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>if(c==0)</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>{</div><div><span class="ecxApple-tab-span" style="white-space:pre">                        </span>renderingEngine-&gt;setChannelWindow(c, float(0), float(255));</div><div><span class="ecxApple-tab-span" style="white-space:pre">                        </span>renderingEngine-&gt;setRGBA(c, 255, 0, 0, 255);</div><div><span class="ecxApple-tab-span" style="font-size:10pt;white-space:pre">                </span><span style="font-size:10pt">}</span></div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>if(c==1)</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>{</div><div><span class="ecxApple-tab-span" style="white-space:pre">                        </span>renderingEngine-&gt;setChannelWindow(c, float(0), float(255));</div><div><span class="ecxApple-tab-span" style="white-space:pre">                        </span>renderingEngine-&gt;setRGBA(c, 0, 255, 0, 255);</div><div><span class="ecxApple-tab-span" style="font-size:10pt;white-space:pre">                </span><span style="font-size:10pt">}</span></div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>if(c==2)</div><div><span class="ecxApple-tab-span" style="white-space:pre">                </span>{</div><div><span class="ecxApple-tab-span" style="white-space:pre">                        </span>renderingEngine-&gt;setChannelWindow(c, float(0), float(255));</div><div><span class="ecxApple-tab-span" style="white-space:pre">                        </span>renderingEngine-&gt;setRGBA(c, 0, 0, 255, 255);</div><div><span class="ecxApple-tab-span" style="font-size:10pt;white-space:pre">                </span><span style="font-size:10pt">}</span></div><div><span class="ecxApple-tab-span" style="font-size:10pt;white-space:pre">        </span><span style="font-size:10pt">}</span></div></div><div><span style="font-size:10pt"><br></span></div><div><div><span class="ecxApple-tab-span" style="white-space:pre">        </span>renderingEngine-&gt;saveCurrentSettings();</div><br class="ecxApple-interchange-newline"></div><div>Basically I want my 3 channel image to be red, green, blue....</div><div>However the first two channels appear as white, whilst only the last is blue... I tried moving the&nbsp;<span style="font-size:10pt">saveCurrentSettings() after each channel call, but no joy.</span></div><div><span style="font-size:10pt">I'm sure it's something simple, but can't figure it out...&nbsp;</span></div><div>Thanks in advance,</div><div><br></div><div><span style="font-size:10pt">Jerome.</span></div></div>_______________________________________________<br>ome-devel mailing list<br><a href="mailto:ome-devel@lists.openmicroscopy.org.uk">ome-devel@lists.openmicroscopy.org.uk</a><br><a href="http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel" target="_blank">http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel</a><br></div></blockquote></div><br></div></div>_______________________________________________<br>ome-devel mailing list<br>ome-devel@lists.openmicroscopy.org.uk<br>http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel<br></blockquote></div><br></div></div></div>                                               </div>
<br>_______________________________________________
ome-devel mailing list
ome-devel@lists.openmicroscopy.org.uk
http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel</div></div>                                               </div>
<br>_______________________________________________
ome-devel mailing list
ome-devel@lists.openmicroscopy.org.uk
http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel</div>                                               </div>
<br>_______________________________________________
ome-devel mailing list
ome-devel@lists.openmicroscopy.org.uk
http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel</div></div></div>                                               </div></body>
</html>